TO UNDERSTAND how mightily Iran once dominated Iraq, head to Ctesiphon, Persia’s old capital, just south of Baghdad. A millennium and a half old, its ruined palace still features the world’s largest unsupported brick arch. Until Arab armies seized it at the dawn of Islam, the city was twice the size of imperial Rome and the centre of a Sassanid empire that stretched from Egypt to the Hindu Kush.

Few Iraqis seem eager to remember that history today. The Persian ruins lie behind rusting barbed wire, as if ties with Iran, past and present, were an embarrassment. Officially, Iran has only 95 military advisers in the country, compared with America’s force of some 5,800 soldiers, several vast military bases and control of the skies. (In reality, an adviser to the prime minister confides, Iran’s forces outnumber America’s at least five to one.)

Iran’s hidden hand is everywhere. One UN official recounts how, after visiting a province near the Iranian border, she was surprised to be told that General Qassim Suleimani, the shadowy commander of the Quds Force, or foreign legion of Iran’s Revolutionary Guard Corps, had been there at the same time. “The Americans are more powerful,” says Hashim al-Hashemi, an Iraqi security analyst in Baghdad, “but the Iranians are more dangerous. They have penetrated every organ of state.”

Their involvement in Iraq has been decades in the making. After Iran’s Islamic revolution in 1979, its ayatollahs recruited Shia exiles whom Saddam Hussein had expelled, and in the 1980s sent them into battle against Iraq. When America toppled Saddam Hussein in 2003, these Iran-leaning exiles headed back to Baghdad, filling the vacuum left by Saddam’s Baath party, which the Americans had banned. America’s withdrawal in 2011 and Islamic State’s routing of Iraq’s army three years later, seizing more than a third of the country, provided more opportunities. As the Sunni jihadists surged south, Shia militias declared a hashad, or “popular mobilisation”, drafting in tens of thousands of volunteers. With the help of arms from General Suleimani, they staved off the fall of Baghdad. Then, to “defend” the country, they seized effective control of much of what remained of it. The acquisitions continue. In March Asaib Ahl al-Haq, one of the largest militias, moved into the riverside palace of Sajjida, Saddam Hussein’s wife, in Adhamiya, a staunchly Sunni neighbourhood of Baghdad. Much of the rest of the capital is already divvied up between 100 or so other militias. Unlike most Iraqi Shias, who profess allegiance to Grand Ayatollah Ali Sistani, in the city of Najaf, many of the militia leaders say they follow Ayatollah Ali Khamenei, Iran’s Supreme Leader, instead. Their men are prone to patrolling Baghdad’s streets as religious police, much like Iran’s hated basijis. Their influence lay behind a countrywide alcohol ban last year. Several of the militias have political representatives in parliament, and for elections in 2018 may band together to form a decisive Iran-leaning bloc. Hadi al-Amari, the leader of Badr, the largest of the Shia armed groups (it claims 20,000 men), still gives orders in Persian, and is a friend of General Suleimani. He too follows Mr Khamenei, though he says that his men are free to choose.

Iraqis first, then Shias?

The practical benefits of adherence to Iran are, however, being tempered with a degree of Iraqi (and Arab) nationalism. Iraq, so Mr Amari says, is too multi-religious to adopt Iran’s system of Shia clerical rule. Other armed groups vow more emphatically to prevent Iran from launching a bid for control of Najaf when Mr Sistani dies. Having Americans around helps reduce dependence on their over-mighty neighbour. When America sent its forces back to Iraq to help with the fight against IS in 2014, most militias welcomed them.

For the moment, too, the hashad brigades have complied with orders to hang back in the operation to retake Mosul in favour of special forces trained by and operating with American, not Iranian, advisers. They let Haider al-Abadi, Iraq’s prime minister and a man who leans much less towards Iran than his predecessor did, take the credit for battlefield gains. And in return for salaries and formal recognition of the hashad as part of the armed forces, their commanders say they will abide by government orders. They have taken down the billboards of Iran’s ayatollahs which loomed over Baghdad’s squares when popular mobilisation was launched.

As they have pushed north beyond Shia heartlands, they have grown more inclusive, incorporating tens of thousands of Sunnis, Christians and Yazidis into the hashad. They have stood by as Mr Abadi, with American cajoling, adopted a more Arab, less Shia-revivalist, foreign policy. Resisting Iranian pressure for visa-free access to Iraq in November, officials turned back Najaf-bound pilgrims without permits, and welcomed the first-ever Saudi plane bringing Saudi Shias to the city. In February the Saudi foreign minister visited Baghdad for the first time in 27 years, and an Iraqi delegation has gone to Riyadh to negotiate restoring cross-border trade.

Yet beyond the tactical alliance over Mosul, all sides are wondering how long the rapprochement will hold. Having rebuilt four big bases, America shows no sign of leaving Iraq; Mr Abadi’s men speak of “a multi-year presence”. On his return from a trip to Washington in March he unveiled plans for demobilising half the 100,000-plus hashad, and integrating what remains directly under army command. Concerned, Iran has sent a new ambassador to Baghdad, who happens to be a senior adviser to General Suleimani. Iranian propaganda videos are circulating, threatening renewed attacks on American bases. Some militias are again proclaiming anti-Americanism. “America’s occupation is accepted by the government, not the people,” says Qasim Musleh, who commands the Ali Akbar brigades based in the shrine city of Karbala. He sees Iran, not America, as Iraq’s ultimate guarantor of stability. Iraq, like Syria, is a theatre where Mr Trump badly needs a clear policy.