Despite the initial skepticism, Khamenei has kept a strong grip on power and has been central in pushing policies that have locked Iran into confrontation with the US.
A demonstrator shows a picture of former presidential candidate Mirhossein Mousavi during a rally in support of Mousavi near the Azadi (Freedom) monument, western Tehran June 15, 2009. [Agencies]
He has personally set policy for the country's nuclear program, drawing the red line that Iran would not give up uranium enrichment, even as the refusal pushed the UN to impose sanctions. He has also strengthened ties with the Palestinian militant group Hamas and the Shiite guerrilla group Hezbollah in Lebanon.
Perhaps Khamenei's most prominent action prior to the election dispute was his role in blunting the popular reform movement that arose in the late 1990s when Mohammad Khatami was elected president and reformists took control of parliament.
Like Mousavi, Khatami was supported by Iran's youth, who demanded a loosening of the strict social rules imposed by the 1979 Islamic revolution and called for improved ties with the outside world, including the country's archenemy, the United States.
Hard-liners backed by Khamenei were able to contain and eventually crush the reform trend. Judges repeatedly closed down liberal newspapers. Khamenei himself stepped in to prevent parliament from amending laws that imposed restrictions on the media.
Unelected bodies directed by the supreme leader were also able to block other key legislation pushed by the liberals. They barred many reformists from running in elections, ensuring the return of hard-liner control of parliament in 2004 and helping Ahmadinejad win the following year.
Khamenei's intervention was seen as the start of the reformists' decline and a signal that the clerical leadership would not allow fundamental change.
But criticism over Ahmadinejad's handling of the economy and his antagonistic attitude toward the international community has re-energized reformists, who challenge the president's 2-to-1 victory over Mousavi. Protesters have staged three days of violent demonstrations in Tehran, setting fires and battling riot police.
Mousavi's supporters aren't the only ones who are upset. The two other candidates, reformist Mahdi Karroubi and conservative Mohsen Rezaei, have also alleged irregularities in the voting. They are backed by Khatami and, perhaps more importantly, Rafsanjani, who heads two powerful clerical government bodies. Rafsanjani is a former ally of Khamenei who has since become a key rival.
Security forces have struck back with targeted arrests of pro-reform activists and by blocking text messaging and pro-Mousavi Web sites used to rally his supporters. But those steps have failed to stem the protests.
Khamenei shifted course Monday when he directed the Guardian Council to look into the allegations of vote fraud. The decision came after Mousavi wrote a letter appealing to the 12-member council, which authorizes election results, and met with Khamenei on Sunday.