Since American-led military forces overthrew the Iraqi dictator Saddam Hussein in 2003, empowering Iraq’s Shiite majority, a crucial question for Iraq and the region was the extent to which it would fall under the sway of Iran, the Shiite theocracy to the east.

Iran gradually expanded its influence in Iraq through a web of political parties, Shiite clerics and militias, and it invested heavily in Shiite religious cities like Najaf, Karbala and Samarra.

When the Islamic State seized a third of the country in 2014, Iran rushed to Iraq’s aid, backing militias that, with the help of Kurdish and American forces, drove the jihadist group out.

Iran sees Iraq as its literal gateway to regional influence — the first stop on a land bridge to its proxies in Syria and Lebanon. More recently, Iraq has been critical to Iran’s survival of painful American economic sanctions, thanks to an American waiver allowing it to buy oil and gas from Iran. Iraq is also a major customer for Iranian goods that are not under sanction, including food and construction materials.

But as Iran’s influence increased and America’s ebbed, Iraq has increasingly chafed at Iran’s presence and its efforts to insert sympathetic politicians into Iraq’s government.

The biggest winner in Iraq’s last election was the party backed by Moqtada al-Sadr, a nationalist cleric who opposes both American and Iranian involvement in Iraq, but the kingmaker was a bloc representing Iraqi militia groups with links to Iran. It was Maj. Gen. Qassim Suleimani, the commander of the elite Quds Force of the Iranian Revolutionary Guards, who brokered the agreement that put the current prime minister, president and Parliament speaker in office.

And four years after the battle against the Islamic State officially ended, the Iranian-backed militias remain. With more than 125,000 armed men, they are now technically part of the government security forces but in reality they have become a force unto themselves.