The Iranian regime's biggest threat may come from the inside.

Ever since the June 12 election, the world has seen signs of serious rifts in the ranks of the Islamic regime in Iran. The main locus of these tensions was between the regime (led by the triumvirate of Khamenei, Ahmadinejad, and the Islamic Revolutionary Guards Corps) and regime defectors like Mir Hossein Moussavi, Ali-Akbar Hashemi Rafsanjani, Mohammad Khatami, and Mehdi Karubi. The opposition repeatedly stood up to Khamenei, defying his orders instead of accepting them as absolute and final. For this transgression, almost 2,000 people are still incarcerated, and at least 20 have been killed in prison and in demonstrations.

During the past week, the Iranian political crisis took a surprising new turn, when the first major rift in the ranks of the triumvirate who engineered the June electoral coup became public. The crisis began when Ahmadinejad, still not sworn in as the new president--or, more accurately, before the “consultative” vote of the people in the general election had been confirmed by the supreme leader--decided to name Rahim Mashai, a man widely understood to be his intellectual guru and also his son’s father-in-law, to the all important position of first deputy president.

Immediately after the Mashai appointment was made public, a chorus of conservative voices demanded its repeal, claiming that Mashai's apparent sins were unforgivable. A few months ago, he had been accused of saying Islam does not have the ability to cope with twenty-first-century problems, and that Iranians have no natural enmity against the citizens of Israel. Ahmadinejad ignored demands for firing Mashai, defending him as one of the most pious men he has ever had the good fortune to meet. Aside from family ties, the two men share a passion for the messianic return of Shiism’s Twelfth Imam.

Khamenei soon sent Ahmadinejad a hand-written note declaring the Mashai appointment null and void. It was a Hokm-e Hokumati, the equivalent of a Papal Bull in Catholicism. Even then, Ahmadinejad chose to ignore the order for a week. The delay caused a minor rebellion in the cabinet, with several ministers, including the powerful ministers of intelligence, labor, and Islamic guidance, demanding that Ahmadinejad sack Mashai. Instead of heeding their advice, Ahmadinejad reportedly left the cabinet meeting in anger, sending Mashai back to chair the rest of the meeting. A few days later, he dismissed the dissenting ministers.

Of the group, the firing of Intelligence Minister Gholam Hossein Mohseni-Ejeyee is the most sensitive and important, since the ministry has become a surprising weak link in the regime’s apparatus of oppression. During Khatami's presidency in the mid-90s, some of the ministry’s rogue elements, particularly those responsible for murder of opposition figures, were tried. Under Mohseni-Ejeyee, appointed by Ahmadinejad to the job in 2005, the ministry has been openly opposed to the broadcast of tortured “confessions” of those arrested during last month's protests, all forced to admit that they had been pawns in a Western master-plan for a “velvet revolution” in Iran. Through leaked stories and occasional comments from “inside sources,” the intelligence ministry has been supporting the claims of the opposition--that the rebellion has been locally bred (rather than engineered by meddling foreigners), the result of perceived irregularities in the election. It is not surprising that after firing Mohseni-Ejeyee, Ahmadinejad went over the ministry of intelligence and said he was unhappy with their work. Even his effort to appoint one of Mohseni-Ejeyee's deputies as acting minister backfired when the man refused to accept the job. Ultimately, Ahmadinejad has been forced to become the acting minister himself for the rest of his term.

Even after a week-long delay in acknowledging Khamenei’s order, Ahmadinejad still did not fully carry it out. He wrote back a note--terse, angry and defiant in tone--declaring that Mashai had decided to resign his post (rather then being dismissed, as Khamenei had decreed). More incredible still, Ahmadinejad appointed Mashai to the important position of his own chief of staff and special advisor to the president--in brazen defiance of Khamenei and nearly the entire top clerical establishment of the regime.

In response, Keyhan, the Tehran daily and a Khamenei mouthpiece, called Ahmadinejad a man of “little knowledge” with “a malleable Islamic vision.” Sobhe- Sadeq, the weekly political organ of the Revolutionary Guards, warned that Ahmadinejad’s legitimacy is “dependent on his acceptance of Velayat-e Fagih” and heeding the supreme leader's wishes. One of the leaders of the parliament went as far as to declared that, with these firings, Ahmadinejad’s administration is no longer “legitimate,” its decisions null and void, and it must seek a vote of confidence if it wants to serve out the rest of his term; it is a kind of a language that could presage an attempt to impeach Ahmadinejad for insubordination. All these tactics are part of a failed attempt by Khamenei to flex his muscles and reestablish the kind of authority he had before the June 12 election debacle.

The events of the past few days reveal the June 12 electoral coup's chickens coming home to roost. The regime handed Ahmedinejad a landslide victory--and he wasted no time in exercising his power accordingly, even against those that manufactured his win. It seems that, like the rest of the nation, he sees the nearing end of Khamenei’s days as an absolutist ruler, and is trying to establish an independent turf of his own.

The developments might bode well for Iranian democracy, and ill for Barack Obama’s Iran policy. Rifts and rancor amongst the ruling elite is often a precondition for democratic transitions; Iran is no exception. Such rifts, however, make the work of “engaging” that country much more difficult; it is hard to engage with a nation if it is not clear who rules it. As the past week has shown, Iranian politics will remain in constant flux for the foreseeable future. The dust must settle before the United States can engage in meaningful discussions with the regime, and events in the last few days have only added to the debris in the air.

Abbas Milani is the Hamid and Christina Moghadam Director of Iranian Studies at Stanford, where he is the co-director of the Iran Democracy Project. His latest book is Eminent Persian: The Men and Women who Made Modern Iran, 1941-1979 (Syracuse University Press).

By Abbas Milani