On June 14, Iran will hold a presidential election. If the acrimony and fraud of the 2009 election was not enough to cast a pall over this vote, then the ongoing power struggle between Supreme Leader Aytollah Ali Khamenei and President Mahmoud Ahmadinejad surely is. Term limits prevent Ahmadinejad from running for reelection, but he refuses to leave office quietly -- he has been grooming his chief of staff and close confidant, Esfandiar Rahim Mashaei, as a successor. Khamenei does not like either Ahmadinejad or Mashaei, seeing them as part of a “deviant faction” that stands in the way of clerical rule. It is a nasty squabble without any heroes, and regardless of who wins, the real loser will be democracy in Iran.

For a period of five days next month, from May 7 to May 11, Iran’s Guardian Council will vet the candidates, choosing who can and cannot run. Mashaei has not yet officially announced his candidacy, since this can be done only during those days, after which the council has ten days to rule on his candidacy.

Mashaei, a young-looking 53-year-old, has a broad range of experience in Iranian government and society. An electrical engineer by training, he worked after the 1979 revolution in Kurdistan and the Iranian province of Western Azerbaijan for the Revolutionary Guards’ intelligence division. He also held positions in the Ministry of Intelligence, as chief of a special department dealing with Kurdistan; the Ministry of the Interior, as a general manager; and on government radio. He got to know Ahmadinejad while working for the Tehran municipality when Ahmadinejad was the city’s mayor.

Mashaei filled several different posts during Ahmadinejad’s first term, from 2005–9, and was appointed vice president at the beginning of the second term. Mashaei’s promotion led to protests on the part of the “sources of emulation,” the primary religious authorities followed by pious Shiites, and the faqihs (Islamic jurists). In July 2009, Khamenei requested that Mashaei be removed from office, but Ahmadinejad refused to dismiss him. Khamenei’s office insisted, writing to Ahmadinejad that the appointment was “contrary to your interests and those of the government and will cause division and dismay among your admirers. You must declare this appointment null and void.”

The supreme leader ultimately got his way, and Mashaei resigned. Ahmadinejad still wanted him around, though, so he appointed him to be his chief of staff in September 2009. Once again, the so-called principlists, hard-liners who support Khamenei, raised their voices in protest, but Mashaei was able to stay on.

Ahmadinejad and Mashaei are clashing with the clerical establishment, but that does not mean that they are fighting for democracy and secular rule. Ahmadinejad is a dictator just like Khamenei. One by one, he has removed the principlist forces and those close to Khamenei from his government, surrounding himself with a loyal coterie. The principlists believe that Mashaei is the guiding hand behind this purge, and they worry that his readiness to buck the conservatives on political, cultural, and social positions presents a grave threat to the Islamic Republic.

What is it about Mashaei that the clerical establishment finds so threatening? First is his defense of Iranian nationalism over Islamism as the guiding force of the country. “Islamism has run its course,” he said in 2004 and repeated in 2008. He also opposes forcing women to wear veils in public. In January 2011, he pointedly asked, “If the veil was not required, what percent of ladies would use it?”

Another of Mashaei’s controversial moments came in July 2008, when he declared that “Iran today is friends with the people of America and Israel,” a statement meant to distinguish himself from the mainstream politics of the Islamic Republic. This matter set off such an uproar that Khamenei delivered a pointed response to Mashaei in a sermon several months later: “This is not right,” he retorted. ”It is illogical. Who are the people of Israel? They are the same people who seize houses, seize land, who seize farms, who seize trade. This is the rabble of Zionist elements.”

The spat extends to the religious sphere, too. Iran’s clerics consider themselves to be governing in the stead of the Twelfth Imam, a messianic figure in Shiism, according to the principle of wilayat al-faqih (guardianship of the jurist). The clergy claims a monopoly on relations with the imam, but Mashaei insists that he, too, has had direct contact with him. The clerics do not like such rivals, so they have accused Mashaei of witchcraft, saying that he acts on commands from satanic genies and has bewitched Ahmadinejad. In mid-2011, 25 of Mashaei’s associates were arrested on charges of practicing witchcraft and economic corruption and sent to prison.

It is against this backdrop that Ahmadinejad began publicly pushing Mashaei’s candidacy several months ago. In December 2012, he appointed Mashaei to head the Non-Aligned Movement’s secretariat, calling him “a monotheist, a believer, pure, patient, of limpid heart and mind, loving and committed to divine values and every person on earth.” This appointment caused a big commotion in Tehran, since it was considered a sign of public support by the president for Mashaei. The specific post is not in and of itself significant -- it is purely ceremonial -- but Ahmadinejad used it as an opportunity to praise Mashaei effusively and make it clear that Mashaei was his chosen successor, provoking widespread objections by conservatives who felt that the president was taking advantage of his position. What is more, critics argued that the praise with which he described his confidant should be reserved for the Prophet Muhammad and not bestowed on a deviant such as Mashaei.

Ahmadinejad and Mashaei’s opponents continue to depict them as opponents of the Islamic Republic and clerical rule. The pair seems to believe that, far from harming them, this characterization might help them win over the country’s pro-democracy movement and urban middle class.

The problem for them, however, is that they have no credentials whatsoever when it comes to democracy and human rights. The urban middle class and the opponents of clerical rule may be happy with the damage that this regime infighting has inflicted on Khamenei -- unlike former Presidents Ali Akbar Hashemi Rafsanjani and Muhammad Khatami, Ahmadinejad has publically stood up to the supreme leader and ignored many of his orders. But they are fully aware of the damage Ahmadinejad and his comrades have done to Iran. Under Ahmadinejad and Mashaei, the country has become even more of an international pariah. All their outrageous slogans against Israel have played right into the hands of Israel’s right-wing prime minister, Benjamin Netanyahu, who has mobilized the West against Iran and regularly urges a military strike. Although the paralyzing economic sanctions that the West brought down on Iran are the result of Khamenei’s demagogic attacks on Israel and the United States, Ahmadinejad’s extreme rhetoric did not help. The people of Iran want peace and a democratic regime, not war and paralyzing economic sanctions.

How will the power struggle play out? If Mashaei is allowed to run, and manages to win, Ahmadinejad might be tempted to follow the Putin-Medvedev model. Just as Dmitry Medvedev was installed as president of Russia for a term, only to cede his place back to Vladimir Putin, Ahmadinejad would love to let Mashaei have a turn as president and then reassume power.

But it is virtually certain that Mashaei will be disqualified. As a result, Ahmadinejad may choose to stand up to Khamenei by dismissing the minister of the interior (who is responsible for running the elections), declaring that the elections will not be held, or resigning from the presidency.

If Ahmadinejad were to try to cancel the elections, Khamenei would directly intervene and decree that they be held. It is unlikely that the governors, who are in charge of the elections in the provinces and are directly appointed by Khamenei, would bet on a losing horse and take Ahmadinejad’s side in such a struggle, thus jeopardizing their political future.

Of course, Ahmadinejad could also attempt to come to some sort of accommodation with Khamenei, which would necessitate his submitting to the supreme leader’s demands, holding elections without Mashaei, and stepping down from power at the end of his term. If he did that, Khamenei might refrain from punishing Ahmadinejad and his allies for insubordination.

Even on the off chance that Mashaei is allowed to run, the cards are stacked against him. Knowing this, Ahmadinejad has considered backing another candidate. But Khamenei will never permit a reformist or one of Ahmadinejad’s allies to become president.