* Rouhani inherits diplomatic tension and failing economy
* Calls for mutual trust-building to ease nuclear dispute
* Faces challenge over release of reform leaders
By Jon Hemming
DUBAI, Aug 1 (Reuters) - A wave of optimism has swept Iran since Hassan Rouhani was elected president last month, but as he takes office on Sunday the moderate cleric has a monumental task to resolve the nuclear dispute, ease stringent sanctions and revive a failing economy.
If that were not enough, he has to do this while trying to satisfy the demands of his reformist allies while outflanking the conservatives he defeated, but who still dominate parliament and are deeply embedded within the state.
But no matter what progress, if any, Rouhani makes towards resolving Iran's myriad problems, President Mahmoud Ahmadinejad's eight years in office are at an end, to the relief of his critics at home and abroad.
Ahmadinejad's abrasive rhetoric and unwillingness to compromise precluded any nuclear deal with the West while ever tightening sanctions, domestic mismanagement and misguided state handouts sent inflation soaring over 40 percent, increasing the suffering of many ordinary Iranians.
"Before the election, everyone was saying anyone, anyone at all, has to be better than Ahmadinejad," said one Tehran resident. "Now people hope Rouhani might be able to change things, at least a bit."
Similar optimism has greeted Rouhani abroad where he has pledged to pursue a less confrontational approach to Iran's talks with six world powers over a nuclear programme the West suspects is a veiled attempt to achieve a nuclear weapons capability. Iran says its efforts are entirely peaceful.
"The historic election of Hassan Rouhani last month in Iran was widely seen as a rejection of radicalism and an embrace of moderation. Hopes have risen that a negotiated solution to the nuclear stand-off may now be within reach," said Trita Parsi, president of the National Iranian American Council.
Rouhani is however very much an Islamic Republic insider with 16 years as head of the Supreme National Security Council and the last eight years as one of two personal representatives of Supreme Leader Ayatollah Ali Khamenei on the same body. Even so, Rouhani has still been making all the right noises.
"Of course our nuclear plans are fully transparent, but we are ready to show more transparency," said Rouhani, setting out his stall at his first post-election news conference. "Second, we will increase mutual trust between Iran and other countries."
"Mutual trust and transparency within the framework of international regulations and principles are the solution to end sanctions," he said. "We will first have to prevent new sanctions being applied, then reduce them and later, God willing, to completely remove them."
Such words however failed to move the U.S. House of Representatives which easily passed a bill on Wednesday to tighten sanctions on Iran, further cutting its oil exports despite warnings from White House officials who said they wanted to give Rouhani a chance.
Rouhani may take some comfort from the reaction of one of the six powers, Russia, which said the U.S. move would not resolve the dispute over Iran's nuclear programme.
Rouhani has also made conciliatory noises about Syria where Iran has provided military training and credit to help President Bashar al-Assad in his more than two-year battle to defeat insurgents supported by Gulf Arab and some Western states.
Praising the Syrian government for standing up to what he called "Israeli expansionist policies and practices", Rouhani has offered to mediate between the Assad "and those in the opposition who strive for democracy and good governance".
The president however has little control over the activities abroad of the Revolutionary Guards who report directly to the leader and have their own independent sources of funds.
Though Khamenei, the top man in Iran's complex power structure, calls all the shots when it comes to nuclear and security issues, the president is given a relatively free hand to run the economy, and that is the big issue for Iranians.
Of course, much depends on Rouhani's ability to gain some wiggle room from swingeing United Nations, U.S. and European Union sanctions that have helped fuel inflation and halved the value of the rial in the last 18 months.
U.S. and EU sanctions are increasingly targeting Iran's oil and gas industry, the life-blood of an economy which generations of Iranian leaders have largely failed to properly diversify.
Ahmadinejad's solution was to wean the country off costly subsidies, a plan applauded by the International Monetary Fund. But poor execution resulted in the government printing money to spend on monthly payments to each Iranian household.
"Since Ahmadinejad took office in 2005, the amount of rials in circulation has increased by a factor of seven. This astronomical growth in liquidity has been a key driver of inflation," said Mohammad Ali Shabani, a UK-based independent Iran analyst.
"This vast stream of liquidity is in constant search of interest higher than inflation, and as such has moved from hard currency, to gold, to property, creating bubbles," he said.
Though the government cash handouts are now much devalued, cutting them altogether, as well as implementing traditional means of battling inflation, could prove extremely unpopular and with revenues from oil and gas squeezed, Rouhani's room for manoeuvre could prove to be limited.
That could build up opposition at home with moderate Rouhani squeezed between hardline conservatives and reformists whose last minute endorsement helped him clinch his surprise win.
As ever, the key will be the stance of the leader. Rouhani and Khamenei go back some 40 years to the intrigues that helped topple the U.S.-backed shah in 1979. But the leader still openly criticised Rouhani when, as Iran's chief nuclear negotiator, he agreed to suspend Iran's uranium enrichment in 2004.
Khamenei has turned against allies in the past. He strongly backed Ahmadinejad in the face of huge protests in which dozens were killed following the 2009 election, then later shunned the president when he appeared to challenge the leader's authority.
Though temporarily down, hardliners are by no means out. Rouhani's first domestic test could be how he handles calls from reformists for the release from house arrest of Mirhossein Mousavi and Mehdi Karoubi, the candidates defeated in 2009.
"I don't think it will be difficult to bring about a condition in the next year where not only those under house arrest, but also those detained after the 2009 elections will be released," Rouhani told students during his campaign in May.
But hardly a day now passes without a hardline member of parliament railing against the 2009 "sedition" and the dire consequences that would befall Iran if its leaders were freed.
Shaul Bakhash, professor at George Mason University in Virginia, said Rouhani was inheriting daunting challenges: A deteriorating economy, a disorganised government administration, a worsened human rights situation, and strengthened hardline and conservative political organisations.
"He has his work cut out for him." (Additional reporting by Marcus George; Editing by Giles Elgood)