Ahmadinejad: Iran's populist and pariah leaves the stage
Mahmoud Ahmadinejad will be replaced as Iran's president in the country's presidential elections late this month. An official visit to Ghana offered a glimpse of what drives one of the world's most divisive leaders, and what he has achieved in his eight years in office.
On the tarmac of Accra's international airport, Mahmoud Ahmadinejad looked unhappy.
In the first few minutes of his visit to Ghana, he had dutifully inspected a guard of honour and listened to the Iranian and Ghanaian national anthems.
Ghana's President John Mahama began to escort him to the terminal building.
But Mr Ahmadinejad made a circular gesture with his hands - he wanted to shake hands with the crowd.
And off he went. Dozens of students in new white t-shirts rushed to say 'hello' to Iran's president. Mr Ahmadinejad started to smile. He is always at his happiest in a crowd - ideally a scrum.
'We love him'
In Accra, Iran's president enjoyed the stage he had spent the last eight years building.
"We love him, we love him, we love him, why don't you like him?" one Ghanaian man shouted.
Mahmoud Ahmadinejad never much looked like a traditional Iranian president. He wore a cheap jacket and a scruffy beard. This made Iran's middle class cringe - and that was the point. Mr Ahmadinejad wanted the support of the little guy - the farmers and taxi drivers of Iran's working class.
"All the presidents before Ahmadinejad were dependent upon Iran's ruling clergy," says Farhad Jafari, an author and prominent supporter of Mr Ahmadinejad.
"But Ahmadinejad was a man of the people. Unlike his predecessors, he understood ordinary Iranians. And he was more committed to the people than he was to the political ruling class."
In his first term, Mr Ahmadinejad decided that he could not defy the clerics who had helped to put him in office. But he could pick a fight with the West. Days after he took office, Iran restarted its nuclear programme.
"He had no fear. No fear!" remembers Hosein Mousavian, a former member of Iran's nuclear negotiating team.
"He said we would start and they [the West] would be able to do nothing. I was really shocked. He was so brave, or inexperienced, about international equations, politics, relations. He clearly didn't give a damn to the UN Security Council to decide on the Iranian nuclear issue. They cannot do anything."
But they did. Over the next few years, the United Nations and the West imposed several rounds of sanctions against Iran.
This did not appear to deter Mr Ahmadinejad. The more he spoke, the more he provoked, the greater his stage became.
"I really do believe that we have taken Ahmadinejad far more seriously than he deserves," says former US ambassador Ryan Crocker, who has engaged with Iran more than any other senior US official in the last three decades.
"He loves it. He loves being outrageous. He loves drawing fire from all corners of the civilised world. But I don't think it really counts for very much in the Iranian policy sphere."
That is because Iran is not ruled by the president. In the Islamic Republic, Supreme Leader Ayatollah Ali Khamenei has the final say.
In the absence of ultimate power, Mr Ahmadinejad needed to find ways of building up his profile. His most reliable technique was to provoke the United States or better still, to engage with it. In 2006, he decided to send an 18-page letter to President George W Bush.
"My recollection is that it was a rambling letter and when the question came up - 'Well, shall we reply to the letter?' - one of the problems was it's hard to know what to reply to," says Steve Hadley, former national security advisor to President Bush.
"Do you really want to respond to a leader who writes you this stream of consciousness letter who is pursuing policies very antithetical to the interests of stability and peace in the region, when everybody knows also that the real decision maker is the Supreme Leader?"
So the letter went unanswered. At home, Mr Ahmadinejad faced even greater problems. In 2009, after his disputed election, he decided to defy his own supreme leader and seek more power for himself and his allies.
"In the eyes of the loyalists to the supreme leader of Iran, Ahmadinejad has no resemblance to the man who became the mayor of Tehran and arose and became a president of Iran," says Taghi Karroubi, son of former reformist candidate Mehdi Karroubi. "They blame him for everything.
"As far as I know, Ahmadinejad always tried to separate himself from the policy of crackdown and violence against the Iranian people during the last four years," Mr Karroubi says.
"We've been told Ahmadinejad wrote a letter to the supreme leader - asking to free the political prisoners, and remove the house arrest of the opposition leader. We don't know - is it right or wrong?"
Satellite into space
For some, it was simple - if Mr Ahmadinejad was not with the clerics, he must be with the reformers. But others view that as a mistake.
"I do not for a moment buy this notion that Mr Ahmadinejad is a secret reformist standing steadfast against the wild-eyed clerics," says Ryan Crocker.
"It's hard to exceed Ahmadinejad in the wild-eyed department, as his statements make so abundantly clear."
Mr Ahmadinejad enjoyed the attention he worked so hard to create. But what, in the end, was there to show for it?
"You fought with the West, with your own supreme leader," the BBC asked the Iranian president in Ghana. "What did you achieve?"
"Despite the all the unfair pressures exerted on the people of Iran, we are making headway very fast," replied Mr Ahmadinejad.
"Since the day they imposed sanctions on us, we have gone nuclear. And now we are making use of peaceful nuclear energy.
"When they imposed sanctions on us, we became a country that has launched satellite into space. The pressures have caused problems for us, but they haven't been able to bring our progress to a halt."
During his eight years in office, Mr Ahmadinejad has been both populist and pariah.
He has provoked both the West and Iran's clerics - but he won neither fight.
Earlier this year, he suggested that he would be willing to become the first Iranian in space. But down here on earth, he is about to lose what he loves above all else - his stage.