Robert Baer served in the CIA as a field operative from 1976 to 1997. His latest book is The Devil We Know: Dealing with the New Iranian Superpower (Crown Publishers, 2008).
In Iran nothing is ever as it seems, including presidential elections. It's arguable that Friday's election had less to do with a vote for or against Ahmadinejad than it did with a vote for or against Iran's Supreme Leader, Ayatollah Khamenei. And if the elections were stolen, it was likely in an effort to maintain Khamenei's hold on power rather than Ahmadinejad's.
Iran is not a theocracy. It is a military dictatorship headed by Khamenei and advised by a coterie of generals from the Islamic Revolutionary Guard Corps and the Army, as well as hard-liners in the secret police. Ahmadinejad is little more than the spokesman for this group. He may have a say in the day-to-day management of the economy and other parts of Iranian administration--but all important decisions, particularly those related to Iran's national security, including rigging presidential elections, are made by Khamenei.
What makes this such a tenuous situation is that Khamenei's legitimacy has been in question from the day he succeeded Ayatollah Khomeini in 1989. It was widely understood among intelligence analysts that Khamenei did not have the religious credentials to succeed Khomeini as supreme leader, Iran's head of state who is supposed to be the most learned religious cleric. In fact, Khamenei is not even really an ayatollah--his license was in effect bought--and he has no popular religious following as other legitimate ayatollahs do. It doesn't help that Iranian leaders of Khomeini's generation have never particularly liked Khamenei and see him as a man who muscled his way into power, perhaps even by killing Khomeini's son, the person most likely to challenge his rule.
A sure signal of Khamenei's political weakness occurred when Ahmadinejad attacked former president Rafsanjani for corruption during the election campaign. Rafsanjani is and always has been a threat to Khamenei's legitimacy. Not only is he more of a real ayatollah, but he is also Chairman of the Assembly of Experts and the Expediency Council, two powerful government bodies. The Assembly of Experts has the power to remove Khamenei and appoint a new Supreme Leader. And though facts are impossible to come by, it is almost certain that Ahmadinejad's attack on Rafsanjani could not have been made without a green light from Khamenei, who knew that charges of Rafsanjani's corruption would strike a chord with Iranians. Khamenei saw and probably still sees Rafsanjani as a threat to his power, even to his position as supreme leader, and this was an effective way to pounce.
Still, if the protests and demonstrations in Tehran cannot be controlled, we should seriously start to wonder about Khamenei's future. Rafsanjani is rumored to be in the holy city of Qum plotting against Khamenei, seeing if he has enough votes in the 86-member Assembly of Experts to remove Khamenei. A vote recount is unlikely to change the results of the election, but it could lead to more demonstrations, which backed by Rafsanjani and the other mullahs, might just end Khamenei's 20 year run.