* Fireworks expected at Ahmadinejad's last U.N. appearance
* President revels in challenges with US media
* Tenure leaves international relations damaged and economy tanking
By Marcus George
DUBAI, Sept 26 (Reuters) - He is loathed in the West and weakened at home, but Iran's outspoken president Mahmoud Ahmadinejad seems intent on raising hackles one more time during his last official visit to the United Nations this week.
With tensions between Tehran and Western powers high due to the dispute over Iran's nuclear programme, his latest blasts against Israel show that the hardline Ahmadinejad has no thoughts of presenting a kinder, gentler face to the world at a delicate moment.
But the 56-year-old - who is struggling through his last year in office after nearly losing his job - has long relished any opportunity to promote his controversial views and to bat back criticism of them.
"Now he's been sidelined at home he will really want to ham it up abroad," said Ali Ansari of Scotland's St Andrew's University, referring to Ahmadinejad's address to the U.N. General Assembly on Wednesday.
Unfazed by walkouts and demonstrations on previous visits to New York, Ahmadinejad has alleged the U.S. government was behind the 9/11 attacks, lambasted Western leaders for being played by "deceitful Zionists", and denied homosexuality exists in Iran.
In contrast to the rhetoric, he has happily engaged with U.S. media, appearing on television and in newspaper interviews.
"There's a lot of ego that drives the blacksmith's son from Iran to take on the might of American television," said Iranian-American author Hooman Majd, who has met him several times.
Since his election victory in 2005, the diminutive president has gone from obscurity to the most visible actor on the Iranian stage. He even survived a disputed re-election in 2009 that rocked the country to its core.
Mocked by progressive Iranians and blamed for severe mismanagement, Ahmadinejad has still created a cult following among some people through his charm, simple lifestyle and populist beliefs.
His fans glorify him as a humble servant who shuns the trappings of power. Ahmadinejad, so the story goes, took office refusing a salary and going to work with a packed lunch.
But such modesty does not extend to his fiery character which lies at the heart of his quest for global recognition.
"He's the first president in Iran that almost everyone in the world knows. That gives him huge satisfaction," Majd said.
Ansari said he was driven by vanity and the need for attention.
"He also believes he speaks the truth and that everyone in the West simply needs to be enlightened," he said.
Ayatollah Ali Khamenei, Iran's most powerful man, initially groomed Ahmadinejad to take on the reformist movement through his devout religious views, his common touch, his accessibility to young Iranians and connections to the military.
One of the attractions for his supporters was his non-clerical status and a down-to-earth image that contrasted with the elite members of the clergy.
Seven years on the political terrain has changed.
Reformists have been sidelined, opposition leaders Mirhossein Mousavi and Mehdi Karoubi are under house arrest, and parliament is compliant, leaving Khamenei in control of all levers of power.
"Ahmadinejad's role was to dismantle the institutions of republicanism in the country, and having gone some way to achieving this, his utility is now over," Ansari said.
Despite his debt to Khamenei, Ahmadinejad's quest for power led him into confrontation with the supreme leader. The feud went public last year after Khamenei reinstated intelligence minister Heydar Moslehi, who Ahmadinejad had sacked.
Khamenei loyalists launched a campaign to undermine the president who has since been frozen out of major decision-making and threatened with impeachment.
"He wants to leaves a legacy where he was the guy breaking the stranglehold of the mullahs," Majd said. "He believes an elected president should be allowed to govern. That's quite a popular sentiment among Iranians."
Economic problems have also piled up.
Ahmadinejad faces an economy ravaged by sanctions, a plummeting rial and inflation that officially stands at 25 percent but which some estimate is closer to 50 percent.
Many criticize him for launching a programme in 2010 to withdraw generous subsidies in favour of cash handouts. Food and fuel prices have soared and households have struggled to cope.
Such was the concern over his performance that in March he was summoned by the parliament for a roasting.
Abroad the Ahmadinejad years have been equally disastrous, putting the country under huge pressure, analysts say.
Confrontation with Israel has intensified and Tehran is one of the few international backers of Syria's President Bashar al-Assad in the conflict there.
"Unfortunately during the Ahmadinejad era the foreign policy of Iran has been damaged, with the West but also with regional countries such as Saudi Arabia, Turkey and the Gulf countries," said Hossein Mousavian, a former nuclear negotiator under President Mohammad Khatami and now a visiting scholar at Princeton University.
The next president needs the Supreme Leader's trust because legally Khamenei is the ultimate decision-maker on major foreign policy and security issues, Mousavian explained.
"It's been an incendiary, combative approach," Majd said. "There's a lot of dissatisfaction as to where the country is going."
Iran restarted uranium enrichment weeks after Ahmadinejad took office in 2005, activities that had been suspended under Khatami. Washington has hinted at military action over what it believes are attempts to develop a weapons capability.
As rhetoric flies back and forth between Israel and Iran, Ahmadinejad misses no opportunity to bash Israel as a "cancerous tumour" and the United States as the world's leading war-monger.
Yet his time in office is notable for his attempts to establish direct contact with two U.S. presidents.
"The most important legacy left during the Ahmadinejad presidency was that the taboo of negotiating with the United States was broken. Since he had a freer hand, he wrote letters to both President Bush and President Obama," Mousavian said.
"Even though his letters went unanswered, it was unprecedented for any Iranian president since the (1979) revolution to make such overtures to the United States."
The direct approaches include meetings between Ahmadinejad advisors and U.S. officials during his first term.
His determination to break the deadlock also led Ahmadinejad to advocate a 2009 nuclear deal that came close to resolving the issue. Ultimately it was shelved after criticism from both conservatives and reformists.
Having served two terms and unable to run again, he says he intends to return to his university post next year. But many believe he cannot resist the temptation to carve a future role in Iranian politics.
"He has a huge ego. He believes he's right and he is unafraid," said Majd, who believes Ahmadinejad may be mulling setting up a political party.
"He's like a boxer who's been knocked down. When you think it's over, he always seems to get up again."