Beyond the power struggle playing out on the streets of Tehran is a complex battle for control of Iran's intelligence ministry -- a pivotal institution in the regime's repression of dissent.
President Mahmoud Ahmadinejad, who began a second term this week, fired Intelligence Minister Gholam-Hossein Mohseni-Ejei late last month after Mr. Ejei objected to the president's efforts to name an in-law as first vice president.
The departure of Mr. Ejei, a hard-line cleric close to Iran's Supreme Leader Ayatollah Ali Khamenei, two other Khamenei loyalists and nearly 20 other high-ranking officials appeared to weaken the leader's hold over the ministry and strengthen the power of the Revolutionary Guards, Iran's elite military force.
The Guards have been heavily involved in the crackdown on dissent since the disputed June 12 presidential election, and there is an unconfirmed report that the force has created a parallel intelligence service called Tehran intelligence. Mr. Ahmadinejad and many of his closest allies are Guards veterans.
Mr. Ejei was responsible long before the elections for jailing numerous Iranians and Iranian-Americans on charges of promoting a so-called velvet revolution. However, he apparently was not loyal enough to Mr. Ahmadinejad.
"Ejei was so hard-line that no one believed he would not be tolerated by the Ahmadinejad camp," said Fatemeh Shams, a political activist and doctoral candidate at Oxford University whose husband is a political prisoner in Iran.
She noted that Mr. Ejei was present on Monday when Ayatollah Khamenei presided at a ceremony confirming Mr. Ahmadinejad's second term.
"Ejei came for the supreme leader, not for Ahmadinejad, because he derives his credibility from [the leader], Ms. Shams said.
In the aftermath of the departure of Mr. Ejei and others -- including the head of counterintelligence -- some Iranian conservatives are blaming him for the government's failure to stop dissent as well as other ministry public-relations bungles.
A conservative Web site, Baztab, attributed the removal of Iran's counterintelligence head to the government's failure to press for convictions on espionage charges of former nuclear negotiator Hossein Mousavian and two Iranian-Americans, scholar Haleh Esfandiari and journalist Roxana Saberi.
Conservatives also have accused Mr Ejei of a disappointing performance in dealing with the post-election riots.
Pro-Ahmadinejad circles quoted by a reformist Web site, Mizan News, stated that the officials were fired for failing to maintain security and repeatedly ignoring information that a large number of Iranians with anti-government backgrounds were traveling to Iran from England in the lead-up to the elections.
"Two weeks before the riots started, the Foreign Ministry reported that it was very suspicious that a significant number of people were traveling to Iran from Britain," Mr Ahmadinejad told a teachers association, according to Mizan News. "But the intelligence ministry did not pursue this matter. The ministry also did not act as it was expected in the recent unrests, and there were blatant cases of negligence."
Mr. Ahmadinejad also criticized the ousted minister for bringing a case in 2007 against Ms. Esfandiari, who was 67 at the time of her arrest and had been visiting her elderly mother.
Supporters of the theory that Ahmadinejad supporters in the Revolutionary Guards falsified election results in the incumbent's favor pointed to Mr. Ejei's dismissal as proof that the Guards have appropriated some of the Intelligence Ministry's functions. Under Iranian law, the president assumes caretaker responsibilities for up to three months in the event a minister is dismissed.
A high-ranking intelligence official named Majid Alavi has been appointed as interim manager and as Mr. Ahmadinejad's personal representative to the ministry. Mr. Alavi is a fluent Arabic speaker who served four-year terms in Saudi Arabia and Sudan before being expelled from the latter, according to the Persian-language news site Roozonline. He also has strongly supported the harsh crackdown on protesters.
Some of the approximately 20 other high-ranking officials who have been fired or forced to retire wrote a letter to the director of the ministry's intelligence protection office, Mizan News reported, expressing fears that Mr Ahmadinejad would erase security files relating to his allies, including the in-law he tried to name as his first vice president.
The latest purge at the ministry is a continuation of Mr. Ahmadinejad's efforts to stack supporters there for the past four years. In the process, he has antagonized intelligence officers who worked in the administration of his more liberal predecessor, Mohammad Khatami, as well as that of conservative pragmatist Akbar Hashemi Rafsanjani, who preceded Mr. Khatami.
Jahan News, a conservative Web site, claimed that a reformist former intelligence officer currently working in the judiciary called a member of the campaign staff of Mehdi Karroubi, a defeated reformist presidential candidate, three days after the election results were announced and advised him to increase the number of protesters on the streets.
"If you can place a considerable number of protesters by the sides of streets, state officials will stand down," the former intelligence official is supposed to have said.
The outcome of the power struggle in the ministry may give a good indication of whether the Ahmadinejad camp will triumph or whether his re-election will turn out to be a pyrrhic victory.
Ervand Abrahamian, an Iran specialist at Baruch College and the author of "Tortured Confessions," a history of Iranian prisons, said that "the people running the Intelligence Ministry are already Ahmadinejad people. ... There is conflict - some conservatives like Rafsanjani just don't like Ahmadinejad's dangerous policies and want to curtail his power, but I don't know if they'd go as far as taking over the ministry."