BEIRUT: It was an extraordinary moment in the history of the Islamic Republic.
Live on state radio, President Mahmoud Ahmadinejad and parliamentary speaker Ali Larijani exchanged insult after insult in the assembly chamber last Sunday as shocked lawmakers shouted their disapproval.
The stormy session peaked when Ahmadinejad aired a video showing Larijani's brother Fazel allegedly seeking a bribe in exchange for political favours from one of Ahmadinejad's closest allies, former Tehran prosecutor Saeed Mortazavi.
But the real struggle that played out amid the accusations and posturing pits Ahmadinejad against the man at the top of the system in Iran - Supreme Leader Ayatollah Ali Khamenei.
In late October, Khamenei warned that any top officials from the three branches of the state who bickered publicly, particularly in the lead-up to a presidential election in June, would be guilty of treason.
Ahmadinejad, approaching the end of his second term and unable to run again straight away but keen to protect his legacy and his welfare, has ignored that warning this month.
"To openly challenge Khamenei publicly is unprecedented. It will have long-term repercussions. It shows that Khamenei does not have the authority he once did," said Abbas Milani, director of the Iranian Studies programme at Stanford University.
"Neither of the previous two presidents ever publicly defied Khamenei the way Ahmadinejad has."
For Khamenei and his powerful supporters in the Islamic Revolutionary Guards Corps (IRGC), each brazen challenge from the president not only erodes their political authority but also tarnishes the image of the Islamic Republic.
The accusations of financial impropriety and corruption among top government officials comes at a time when economic sanctions, imposed by Western powers seeking curbs on Tehran's nuclear programme, are biting hard in Iran and millions of ordinary Iranians are struggling to make ends meet.
The impression that top government officials are embezzling money rather than addressing the needs of the masses could lead to unrest, analysts say.
"Khamenei is afraid that with the bad economic situation, the economic disgruntlement could turn into political disgruntlement," said Mehdi Khalaji, a senior fellow at the Washington Institute for Near East Policy.
Instead of following the government line and blaming Western sanctions for their economic woes, people might start to blame the politicians: "This is a big worry for him," Khalaji said.
At stake for Ahmadinejad is not only his political legacy for the two terms he served as president but also his welfare and the welfare of a tight-knit circle of political allies once he leaves office.
Many of his top allies face serious legal charges and could serve jail time. Some have already gone to jail.
Ahmadinejad himself could face charges because of his behaviour in parliament this week.
Last Tuesday, judiciary head Sadeq Larijani, the brother of the parliament speaker, held an emergency meeting with the Supreme Leader, according to Fars News, a semi-official news outlet linked to the Revolutionary Guards.
In a meeting with judiciary officials the following day, Sadeq said that he considered Ahmadinejad's actions to be a crime but he would not pursue the issue for now at the behest of the Supreme Leader.
"Even though the accusations of the president toward the judges of the judiciary, the representatives of parliament and the heads of the branches were lies, defamatory and against all legal standards, which I consider a crime, I will keep quiet for now in the interests of the regime and to adhere to the orders of the Supreme Leader," Sadeq said, according to Fars News.
"And at another time I will speak about the details of this matter," he added. Sadeq went on to say that he would expose the "economic, ideological and operational corruption" of Ahmadinejad's allies.
The roots of the conflict go back to the 2009 presidential election when tens of thousands of Iranians poured into the streets to dispute Ahmadinejad's victory over reformist candidate Mirhossein Mousavi.
At the time, the Supreme Leader faced a stark choice: support Ahmadinejad or cast him aside. Khamenei chose to go all in. What followed was a bloody crackdown, which led to the deaths of dozens of protesters and the jailing of hundreds more.
Even though Khamenei sacrificed enormous political capital to keep Ahmadinejad in power, he got little loyalty back.
In the spring of 2011, Ahmadinejad dismissed intelligence minister Heydar Moslehi, a close ally of the Supreme Leader. Within days, Khamenei intervened and reinstated Moslehi, leading Ahmadinejad to boycott cabinet meetings for over a week.
After the feud spilled out into the open, Khamenei loyalists went after Ahmadinejad and arrested more than a dozen officials linked to his controversial former chief-of-staff and key adviser Esfandiar Rahim Mashaie.
The pressure kept building.
In the autumn of 2011, Ahmadinejad's opponents tried to link Mashaie to a $2.6-billion dollar embezzlement scandal, the largest in Iranian history, and he could still face charges in that case. Last September, Ahmadinejad's top media adviser, Ali Akbar Javanfekr, was jailed for printing articles critical of the law which mandates the Islamic veil for women in Iran.
And just this week Mortazavi, the notorious Tehran prosecutor once dubbed the "Butcher of the Press" by reformist critics in Iran for his role in jailing dozens of journalists, was arrested and sent to the Evin prison, a facility where he had sent many others.
He was taken in on charges of financial corruption, Fars News said. Mortazavi, now at liberty again, also faces criminal charges over the deaths of protesters at the Kahrizak prison in the crackdown following the disputed 2009 election.
If Ahmadinejad loses his struggle with Khamenei, these allies will go down with him, analysts say.
"When Ahmadinejad's term as president is finished, the judiciary will go after them one by one," said Khalaji. "Ahmadinejad knows that if he becomes a former president who is marginalised and without any power, all of his key people will be wiped out."
So far, Ahmadinejad's main tool in fighting back has been the political dirt he has dug up and threatened to use on his rivals, a tactic he has employed often with great effect, and which his critics have dubbed "begam begam", which roughly translates as "I'll tell, I'll tell."
After the clash in parliament last Sunday, one Ahmadinejad ally at the Ministry of Interior said that there were 1,000 more damaging documents that the president could reveal, according to reports in the local media.
"He wants to make it extremely costly for the regime, if not prohibitively costly for the regime, to go after him and his coterie," said Milani at Stanford.
And the best way to protect himself and his group is not only to intimidate rivals with secret files and documents but also to keep some of his people in the government if he can, analysts say.
Ahmadinejad has long backed his key adviser Mashaie, who is also a relative - Mashaie's daughter is married to Ahmadinejad's son - as a possible successor as president.
But Mashaie is loathed by many hardliners for his controversial statements, such as a 2008 comment that Iranians and Israelis were friends. It is unlikely that he could pass the stringent vetting process to stand for election.
Still, Ahmadinejad could try to bring his supporters into the street to get a candidate of his choosing in the running. After the arrest of Mortazavi earlier this week, some 50 Ahmadinejad supporters protested in front of the judiciary offices, according to local media reports.
While the chances of an Ahmadinejad-endorsed candidate getting on to the ballot are slim, it is even less likely that any candidate from the reformist camp will be allowed to run. The top two reformist candidates from the 2009 election, Mousavi and Mehdi Karoubi, have been under house arrest for two years, accused of fomenting unrest after the vote.
Khamenei and the Revolutionary Guards are likely to keep a close eye on the vetting process for candidates and voting in this presidential election because of the high stakes, analysts say: "This will be the most rigged election in the history of the Islamic Republic," said Khalaji.
In the feud between the president and the Supreme Leader, a potential role of arbiter is filled to some extent by the Revolutionary Guards, who control vast swathes of the economy and are the most powerful security force in the country.
For now, the Guards have not entered the fray but they might, especially if there is unrest in the upcoming elections.
In an interview with the Qanoun newspaper in mid-January, Revolutionary Guard commander Nasser Shabani said the Guards expected unrest linked to the elections to start from provincial towns rather than Tehran - unrest which could start with grass roots complaints, but which the Guards had already warned potential candidates not to stir up.
Shabani also issued a stark warning to Ahmadinejad.
"Ahmadinejad, for all the good he could have done, is transforming from an opportunity into a threat to the regime, unfortunately. This is an important point," he said, according to the Qanoun interview.
"Overall we must pray that his fate turns out well. And that he returns and boards the ship of the revolution."