Local calls for Haider al-Abadi's removal -- including one by his predecessor as prime minister Nuri al-Maliki -- had been growing as he pursued a reshuffle aimed at addressing graft, which became a major issue after oil prices collapsed in 2014 and strained the government's finances as it launched a costly campaign against Islamic State.
However, the two old adversaries -- Washington and Tehran -- put pressure on their respective allies in Iraq not to unseat Abadi as he seeks to fill the council of ministers with technocrats, according to politicians, diplomats and analysts.
Sources familiar with the matter said U.S. and Iranian efforts helped stave off an attempt last week to unseat Abadi by Maliki, the head of the Shi'ite Dawa party who controls nearly a third of the seats in parliament. Maliki denied the attempt.
The move, which threatens to weaken patronage networks that sustain the elite's wealth and influence, shocked the political establishment that has ruled Iraq since the removal of Saddam Hussein, including Abadi's own Dawa party, the Shi'ite Islamic Supreme Council of Iraq (ISCI), and the Kurdish alliance. After voting Abadi into office two years ago, these parties want a say in how the government is formed.
U.S. Vice President Joe Biden and Iranian Major-General Qassem Soleimani had already made clear before Abadi's cabinet announcement that no attempt should be made to unseat him, so as to keep up momentum in the war on Islamic State, sources with knowledge of the matter said.
Despite sitting on some of the world's largest oil reserves, Iraqis face unemployment, power cuts and poor public services, fuelling resentment against a ruling class accused of squandering revenues earned over a decade of high oil prices. The country ranks 161 out of 168 on Transparency International's Corruption Perceptions Index.
Aside from the United States and Iran, Abadi has also drawn on powerful sources of domestic support. The nation's top cleric, Grand Ayatollah Ali al-Sistani, gave him cover last summer to make reforms following street protests demanding better public services.
Though frustrated with the premier's failure to take decisive action, Sistani's backing has not wavered, according to politicians and analysts.
The Americans, the Iranians and Sistani all had the same view: "Abadi stays in power and puts new ministers in," said Sajad Jiyad, an analyst who advises the premier.
IN PUBLIC AND PRIVATE
On Wednesday evening, hours before Abadi announced his planned cabinet, Maliki signalled that the premier could be ousted with the consent of other blocs, senior officials said.
He was demanding a complete change of the government including Abadi, said Hussein al-Shahristani, outgoing minister of higher education. Mowaffak al-Rubaie, a senior Shi'ite lawmaker, said Maliki was even willing to accept a replacement from outside the Dawa party.
A spokesman for Maliki denied he had tried to unseat Abadi last Wednesday but said the State of Law coalition he leads would not block other parties from replacing him "as long as the political process is preserved".
But Abadi stood firm, boosted by a call from Biden on Wednesday evening whose message Jiyad said was resounding: "You're our last hope in Iraq."
Asked about the call, a Biden aide declined comment.
"The administration has signalled at all levels that efforts to replace the prime minister or... other steps that would paralyse the government would be deeply counterproductive to Iraq's stability and the joint campaign to defeat" Islamic State, the aide said in Washington.
U.S. efforts to ensure Abadi didn't fall were "very active" in the days before Thursday's announcement, a Western diplomat said. Rubaie said that would need to continue this week to ensure the Kurds and Sunnis approve the new cabinet.
Brett McGurk, U.S. envoy to the anti-Islamic State coalition, discussed the political crisis with Kurdish regional President Massoud Barzani on Sunday before visiting Baghdad for talks with more officials. A U.S. Congressional delegation to Iraq also met government and military officials including Abadi.
There was interest in a strong Iraqi government headed by Abadi that can continue the fight against Islamic State, a senior U.S. diplomat in Baghdad told Reuters.
Iran has conveyed a similar message to Iraqi politicians. Soleimani, commander of the elite Quds Force responsible for protecting Iran's interests abroad, met representatives of Maliki and ISCI leader Ammar al-Hakim, said a Shi'ite politician familiar with the discussions.
"Both the Americans and the Iranians wanted to avoid Abadi getting unseated," said Jiyad.
SADR'S RISING STAR
Abadi was also emboldened to sack his politically appointed cabinet by pressure from the followers of another powerful Shi'ite cleric, Moqtada al-Sadr.
Dismayed with the slow pace of reforms, Sistani had decided in early February to stop addressing politics in his weekly sermons as a way to prod Abadi into action.
Sadr, who rose to prominence a decade ago when his followers fought U.S. troops, quickly filled the silence. He rallied supporters to sit in at the gates of Baghdad's fortified Green Zone, which houses embassies, government offices and parliament.
He then launched his own five-day sit-in under a tent inside the Green Zone to force Abadi to draft a government of technocrats and warned party leaders they would face street protests if they obstructed him.
Abadi went to parliament on Thursday with the full cabinet line-up in one hand and a second partial reshuffle in the other, two lawmakers said. After a 90-minute meeting with the parliament speaker, he emerged with the full list and asked lawmakers to accept, reject or amend it.
As if on cue, Sadr ended the sit-ins with a speech from his tent, praising the prime minister's move as "courageous".
Parliament has said it will take ten days to review Abadi's nominations, who are not well-known and were chosen without consulting the political parties.
On Friday the candidate for oil minister withdrew under apparent pressure from Kurdish leaders who objected to having no say in who would represent their community.
Most political groups are not happy with nominees put forward without consultation, except for the Sadrists, who also said Abadi's list could be amended so long as new candidates are not affiliated with political parties.
Lawmakers and analysts expect parliament to reject up to half the list, but that will not be an issue for Abadi as long as he eventually gets enough politically independent experts in place.