When most Americans think of Iran, they think of its incendiary president, Mahmoud Ahmadinejad. Since his election in 2005, Ahmadinejad has gleefully shocked the world with his defiance over Iran's nuclear programmes, ravings about a Shiite messiah, jeremiads against Israel and denial that the Holocaust occurred.

But while Ahmadinejad is surely the regime's face, he's not its boss. Since Ayatollah Ruhollah Khomeini's death in 1989, the real power in Tehran has belonged to the country's supreme leader and top cleric, Ayatollah Ali Khamenei. Ahmadinejad makes all the noise, but Khamenei holds all the strings.

It's not just laypeople who assume that Ahmadinejad calls the shots in Tehran. Last Tuesday, as the US President George W. Bush tried to explain away a new National Intelligence Estimate reporting that Iran had shuttered its nuclear-weapons programme back in 2003, he argued at an awkward news conference that his administration's "carrot-and-stick approach" towards Iran had been working - "until Ahmadinejad came in". But under the Iranian system, a president matters far less than the supreme leader. For all Ahmadinejad's bluster, he is not "the decider". It's the unelected and unaccountable Khamenei who sits atop Iran's labyrinthine political structure. He gets the last word on whether Iran should try to get the bomb or try to talk to the United States. So to deal with Iran, the West must get to know Khamenei.

The supreme leader is an enigma even to most of Iran's 70 million people. In fact, he's far more cautious, conservative and pragmatic than the bellowing Ahmadinejad. Khamenei wants a "Goldilocks" kind of Islamic Republic - not too hot, not too cold. He's reluctant to tilt too far in any one direction and keen to keep squabbling factions on board. He says that nuclear weapons are un-Islamic but heartily approves of the knowledge and fuel required to build them. And he is even willing to work with the US to bring stability to Afghanistan and Iraq - so long as Iran gets to expand its regional influence by keeping its feeble neighbours under its thumb.

So how does Khamenei get along with Ahmadinejad? For now, at least, the supreme leader is standing behind his demagogic president. Khamenei decidedly prefers the populist, hardline Ahmadinejad to his relatively moderate predecessor, Mohammad Khatami. The supreme leader frustrated Khatami's attempts at reform and ensured that Ahmadinejad (then Tehran's mayor) would win the 2005 presidential elections. Khamenei has praised Ahmadinejad's administration as the best yet, partly because the two men share a soft spot for militant types and dream of rekindling the revolutionary fervour of the Islamic Republic's early days. The supreme leader even sometimes seems to find Ahmadinejad's theatrics useful for keeping up revolutionary appearances and endearing Iran to the Arab world.

Still, the two men's agendas differ importantly. Ahmadinejad, for example, aspires to be more than a mere administrator. Khamenei, however, already holds all the power he wants and merely needs to keep it away from ambitious presidents, whether hard-line or reformist. Moreover, Ahmadinejad's brand of rabble-rousing may be a useful strategy for a newcomer trying to elbow his way toward greater influence within the tangles of the Iranian political system, but it has deepened Iran's isolation abroad in ways Khamenei resents. For instance, he bristled during Ahmadinejad's December 2005 visit to Makkah, when the president embarrassed his welcoming host, Saudi King Abdullah Bin Abdul Aziz, with a Holocaust-denying, anti-Israel harangue. Closer to home, when Ahmadinejad recently had the country's former top nuclear negotiator, Hossein Mousavian, arrested on espionage charges, an irked Khamenei ensured that the judiciary dismissed the charges.

So Khamenei is keeping his options open. He's helped boost Ahmadinejad's rivals in the 2005 race, Ali Akbar Hashemi Rafsanjani and Mohammad Bagher Ghalibaf, by giving the former's Expediency Council (a key clerical panel) more powers and by backing the latter's bid to become Tehran's mayor. Both men remain serious contenders for power and take every opportunity to snipe at Ahmadinejad. So do a growing number of Iran's elite, who abhor Ahmadinejad's mismanagement of the economy and fear that his bluster has increased the chances of war with the United States. The president's foes hope to drub him in the parliamentary elections coming up in March.

Meanwhile, the decider is getting old. As Khamenei pushes 70, rumours abound that his health is deteriorating. One of the usually dull elections to the obscure Council of Experts, the mysterious body that will choose his successor, recently turned into a closely watched race. (Moderates won.) Still, experts can only guess at who will follow Khamenei - and about whether Iran's next supreme leader will reign supreme.

Enemies all around

For now, Khamenei sees enemies all around: dissidents at home eager to reform the Islamic Republic out of existence, Sunni Arab states galvanised by the rise of Iranian influence, a Bush administration still obsessed with regime change despite last week's National Intelligence Estimate painting Tehran as toothless. Khamenei's greatest fear has always been that his enemies at home and abroad would join forces. (Little wonder, then, that he rejected talking to the US when it looked as if the Clinton administration wanted to engage only Khatami and the reformists whom the supreme leader so fears.) Khamenei has done a nasty, effective job of sidelining the reformists, but he still faces the challenge of the US.

In the past, Khamenei has not been averse to talking to Washington. He gave tacit support to an ill-fated memo offering direct US-Iranian talks in 2003, and a year later, he publicly endorsed discussions over Iraq. But times changed after Iran dug in its heels over the nuclear issue and found itself looking down the barrels of US guns. The threat of war has abated, but for the man who rules Iran, two overriding concerns linger: ensuring that his regime survives and ensuring that he remains at the head of it. As the National Intelligence Estimate itself put it, "Tehran's decisions are guided by a cost-benefit approach rather than a rush to a weapon irrespective of the political, economic, and military costs." But Tehran's decisions are also guided by one man, and anyone serious about understanding the sources of Iranian conduct needs to keep an eye on him.

Vali Nasr, a professor at the Fletcher School of Law and Diplomacy of Tufts University, is the author of 'The Shia Revival: How Conflicts within Islam Will Shape the Future'.