Dictatorial and divisive, the Iranian president Mahmoud Ahmadinejad is an undaunted personality. But the courage and self-belief of Khamenei's unruly protégé are being put to the test as he gears up for renewed nuclear talks and subsidy reform.
Ahmadinejad: Khamenei's unruly protégé
Iran's ambitious president, Mahmoud Ahmadinejad, often proclaims that there are only two major world powers now: his country and the United States. And Iran, he predicted in a recent interview with state television, would gain overall supremacy within 15 years.
Populist yet authoritarian, the quixotic, polarising and unpredictable son of a village jack-of-all-trades has been accused of many things during his turbulent five years in office. Lacking self-confidence is not one of them.
When he first took office in 2005, his declared ambition was to revive the revolutionary spirit that infused the country after the establishment of the Islamic Republic in 1979. That spirit, he said, had waned during the tenure of his reformist predecessor, Mohammed Khatami.
Today, analysts say, he views himself as nothing less than an historic leader who will restore Iran to the ranks of a world superpower as it was during the Persian Empire, even as it spreads the message of Islam worldwide.
In the coming months, Mr Ahmadinejad, 54, will need all the self-confidence and sense of mission he can muster to address the challenges he faces at home and abroad.
Tehran is due on December 5 to resume long-stalled nuclear talks with six world powers, led by the United States. If the talks fail, US or Israeli military action is possible.
The prospects for a peaceful resolution to this stand-off are bleak, and opponents of the president underestimate the diminutive Mr Ahmadinejad - he is 1.62 metres tall - at their peril. He insisted last week that Iran would not discuss its nuclear programme and would only talk about resolving "international problems" to help bring global peace and security.
Domestically, his government is scheduled later this month to start slashing food and fuel subsidies, which many low-income Iranians regard as their birthright. It is a bold move for a populist like Mr Ahmadinejad, whose management of Iran's oil-rich economy has been widely criticised.
He claims the cuts will improve the lives of the nation's poor, the main source of the political support that led him to win by a landslide five years ago. But any backlash over rising prices may be far more difficult to contain than the unrest that followed Mr Ahmadinejad's disputed election victory last year.
Certainly, Mr Ahmadinejad tries to lead by example. Married with two children, he prides himself on leading an austere life. When he came to power, he revealed that he drove a battered Peugeot and insisted in receiving dignitaries at his modest office, ending the practice of welcoming them at the ousted Shah's marbled palace in northern Tehran.
He is also a workaholic who is said to survive on just four hours of sleep. More than once, he has been hospitalised with exhaustion, his aides admitted two years ago.
For all his dedication to the job, however, no president in the history of the Islamic Republic - he is the sixth - has been as divisive as Mr Ahmadinejad.
Even before last year's election, he had "failed to transform his populism into any form of democratic legitimacy", noted Dr Ali Ansari, an Iran expert at St Andrews University in Scotland.
For the time being, pressure by Iran's security forces and intelligence services has neutralised the threat from reformist politicians and millions of ordinary Iranians angry about last year's election. His regime is threatened more by disagreements with fellow conservatives, some of whom acknowledge that he has been useful in emasculating the reform movement that flourished under Mr Khatami but believe his foreign policy has been recklessly aggressive, pointing to United Nations Security Council sanctions over Iran's nuclear programme.
More importantly, they say he is trying to monopolise power in the presidency, riding roughshod over the parliament and other conservative-dominated power centres.
Mr Ahmadinejad has also alienated many of Iran's clerical elite. Some ayatollahs were angered by his crackdown on reformists and fear that he is strengthening the Revolutionary Guards at their expense.
Other, more hard-line clerics, are suspicious of some of his social policies. In his first term, their uproar made him back off a plan to allow women spectators into football stadiums. Last year, they were angered when he appointed three women to his cabinet, one of whom won parliamentary approval.
Clerics and fellow conservatives also have lambasted Mr Ahmadinejad for his steadfast support of his controversial chief of staff, Esfandiar Mashaie, the father-in-law of his eldest son. Mr Mashaie recently infuriated hard-liners by speaking of an "Iranian school of thought" rather than an Islamic one, which angered many clerics because the term smacked of secular nationalism.
Iran scholars believe Mr Ahmadinejad's self-confidence is delusional. They are unsure how serious he is when he declares that Iran, where jails are packed with political dissidents, journalists and students, "is the freest country in the world".
Or when he claims that America is a dying power and he will be a global peacemaker in a fairer, new world order led by Iran and other emerging powers. It is almost as if he lives in a "parallel universe", Dr Ansari of St Andrews University said.
Recalling his first speech before the UN General Assembly in 2005, Mr Ahmadinejad claimed that a halo-like celestial green light descended on him as he addressed world leaders who, he said, sat transfixed for 30 minutes as he spoke. His opponents have long used this recollection to portray him as a hallucinating zealot who believes he has a divine mission.
Indeed, much of Mr Ahmadinejad's combative rhetoric seems to stem from his conviction that the 12th Shiite Imam will soon return to Earth to redress the world's problems. This Messianic world view, analysts say, animates many of his decisions.
He is highly unpredictable, too. A year ago, Mr Ahmadinejad appeared to back a uranium fuel-swap deal with the West but backed off when his conservative opponents attacked it. He also has sent mixed messages to Washington. Aware that better ties with the "Great Satan" would be popular at home, he congratulated Barack Obama, the US president, after his 2008 election. But at a meeting of the UN General Assembly in September, he infuriated Americans by suggesting that the US government was responsible for the September 11 terrorist attacks.
Such grandstanding, however, has alienated most Arab governments, which have long been wary of Iran's regional ambitions and are sceptical of Mr Ahmadinejad's insistence that Iran's nuclear programme is solely peaceful.
Ultimately, Mr Ahmadinejad's political survival depends on continued support from Iran's supreme leader, Ayatollah Ali Khamenei. There have long been rumours of friction between the zealot cleric and the layman president, but the Ayatollah effectively tied his fortunes to his unruly protégé when he publicly gave Mr Ahmadinejad's disputed re-election last year his seal of approval.
So even if Ayatollah Khamenei wants a more flexible domestic and foreign policy - and there are no indications he does - he is unlikely to say so before Mr Ahmadinejad's successor takes office in 2013.
During a recent visit to Qom, the supreme leader staunchly backed his president. An analyst in Tehran, who declined to be identified because of the sensitivity of the subject, observed: "This was a sign that Khamenei approves of Ahmadinejad's aggressive anti-American, anti-British and anti-Israeli foreign policy and his uncompromising stance on the nuclear issue."
How much public support Mr Ahmadinejad has after five years in office is impossible to determine. While huge crowds gather for his public appearances - much of them bussed in, his opponents say - there have been no independent opinion surveys in more than a year.
His legacy is uncertain, too. His anti-American and anti-Israeli rhetoric have impressed many in the Middle East and Muslim world. His tough stance on the nuclear issue, meanwhile, has saddled Iran with economic sanctions and exposed it to the threat of military action.
Domestically, he has done what many thought was once impossible: stuffing the genie of political liberalisation that flourished under Mr Khatami back into the bottle. For most Iranians, however, an assessment of his rule will depend on whether he delivers on his promises to boost their standard of living. That verdict will come well before is second term ends.