Mosul is back in the Iraqi government’s hands and the war against Isis seems to finally be approaching its end. This is the good news. But one of the by-products of the campaign is that Iran’s reach now extends even deeper throughout Iraq and seems unlikely to go away any time soon.

A crucial fighting force in the battle for Mosul and other areas liberated from Isis was provided by paramilitary groups that receive supplies and support from Iran, and cross the Iran-Iraq border at will. These were sanctioned by the Iraqi government in November 2016 and made part of the Popular Mobilisation Forces, a coalition of paramilitary groups, some of which have multiple loyalties.

Abu Mahdi al-Muhandis, a paramilitary commander who is considered one of Iran’s closest Iraqi allies, declared on 4 July that the Popular Mobilisation Forces will not go away, even if the government orders them to dissolve. Muhandis’s statement essentially amounted to Iran saying that it plans to protect its interests in Iraq for years to come. These units, and the political forces that are associated to them, intend to prevent Iraq from establishing its own independent security policy, which could limit Iran’s ability to support its allies in Syria and elsewhere.

Mosul after the war: 'Utter and total devastation'

But many Iraqis are not happy to see Iran working in their country through local armed groups. This is not just a sectarian issue, either. Many Shias want to see Iran’s influence limited. In addition to historical animosities and theological differences with Iran, most Iraqis – Sunni and Shia alike – are exhausted by decades of conflict, and worry that Iran’s meddling will promote confrontation.

Ahead of next year’s general election, a large majority of Iraq’s political forces are seeking to reinforce their independence from Iran. Prime Minister Haider al-Abadi, who can take credit for the recent victories against Isis, has long had strained relations with Iran. Now he has become a critic of lawless behaviour in some elements of the security forces, including Iranian-backed groups. His government’s position has been to strengthen state institutions and to reinforce the chain of command.

Meanwhile, Ammar al-Hakim, one of Iraq’s leading politicians and the scion of one of the country’s most prominent Shia families, announced in late July that he would leave the Supreme Islamic Iraqi Council, a political party that his family founded in Tehran with Iranian assistance in the 1980s. He has also formed his own party, from which he continues to establish his independence from Iran.

The Sadrist movement, which represents millions of poor Shia Muslims in Baghdad and throughout southern Iraq, has also openly aligned itself in the anti-Iranian camp. The grass-roots movement’s leader, Moktada al-Sadr, paid a visit this summer to Saudi Arabia, Iran’s biggest regional rival. He also visited the United Arab Emirates, another Sunni state that opposes Iran. These trips were intended to help develop bilateral relations and, thus, Iraq’s independence from Iran.

The only major political coalition to have formally adopted a pro-Iranian approach is led by former Prime Minister Nouri al-Maliki. Since leaving office in 2014, Maliki has been tainted by the armed forces’ humiliating defeat by Isis, for which he has rightly been blamed, and which has affected his popularity. He has since sought to reinvent himself as the patron saint of a pro-Iranian militant Iraq that is in confrontation with an ever-growing list of conspirators, including Saudi Arabia, Israel, the Kurds and the United States, among others.

With nearly all of Iraq’s political forces lined up against Iran in 2018, it looks likely that the pro-Iranians will be trounced at the ballot. And yet it looks just as likely that this will have little effect on Iran’s influence in Iraq.

In Iraq’s electoral system, it’s very difficult for any one alliance to take much more than 20 per cent of the vote. This means the various alliances must engage in horse trading and coalition building to form a government. As parties try to secure lucrative ministries, they will lose sight of the goals that they campaigned on – like Iraqi independence. Like every government formed since the invasion in 2003, the next one will be made up of parties pulling the country in different directions. It is a recipe for inaction – and Iran will prey on this.

Neither the United States nor Saudi Arabia nor any other country will be able to have a decisive influence. Outside countries have consistently failed to positively influence Iraqi politics. If these parties really want to prevent Iranian influence, they should provide assistance to security units, like the counter-terrorism service, which has been by far the most effective force against the Islamic State. The continued success of professional security services, rather than Iran-backed paramilitary groups, will allow for Iraq to guarantee its own security.

Against this backdrop, there remains one wild card that could present a real challenge to Iranian domination: intervention by Grand Ayatollah Ali al-Sistani, Iraq’s Shia spiritual leader.

In 2014, Ayatollah Sistani issued a fatwa that called for Iraqis to defend the country against the Islamic State. In response, tens of thousands of Shias joined the army and other groups, including pro-Iranian paramilitary forces. The fatwa’s unintended effect was to give these groups some form of religious legitimacy. Many commentators have speculated that Ayatollah Sistani may now be on the cusp of rescinding his fatwa, which could, in turn, force the Popular Mobilisation Forces to dissolve.

In pictures: Isis' weapons factories Show all 11 1 /11 In pictures: Isis' weapons factories In pictures: Isis' weapons factories A mortar round fin manufactured by Isis in Gogjali, Mosul, November 2016 Conflict Armament Research In pictures: Isis' weapons factories Isis rocket components discovered in Gogjali, Mosul, Iraq in November 2016 Conflict Armament Research In pictures: Isis' weapons factories Isis mortars discovered near Karamlais, Iraq, in November 2016 CAR In pictures: Isis' weapons factories An Isis rocket launch frame in Qaraqosh, November 2016 Conflict Armament Research In pictures: Isis' weapons factories A memo from Isis' COSQC on quality control at a manufacturing facility in Gogjali, Mosul, November 2016 Conflict Armament Research In pictures: Isis' weapons factories Electrically-operated initiators manufactured by Isis in forces Gogjali, Mosul, November 2016 Conflict Armament Research In pictures: Isis' weapons factories Isis mortar tubes at a manufacturing facility in Karamlais, November 2016 Conflict Armament Research In pictures: Isis' weapons factories An Isis mortar production facility discovered in Gogjali, Mosul, in November 2016 Conflict Armament Research In pictures: Isis' weapons factories An Isis weapons manufacturing facilities near Mosul in November 2016 Conflict Armament Research In pictures: Isis' weapons factories Stocks of French-manufactured Sorbitol, Latvian potassium nitrate and Lebanese sugar at an Isis weapons factory in Iraq Conflict Armament Research In pictures: Isis' weapons factories A destroyed Isis weapons facility in Qaraqosh, Iraq, November 2016 Conflict Armament Research

For now, that seems unlikely. The Popular Mobilisation Forces enjoy broad legitimacy for their contribution to the war effort, and many Iraqis prefer that they be maintained as part of the official security forces. Even Abadi has opposed any such dissolution for many of these same reasons.

But a new fatwa from Ayatollah Sistani, following the total liberation of Iraqi territories from Isis, could redefine the obligations of those Iraqis who volunteered in 2014 as being to support Iraq’s army and police – which prohibits Iraqis from engaging in any actions that would undermine Iraq’s national sovereignty. Abadi has already insisted that the Popular Mobilisation Forces are prohibited from acting outside of Iraq. If the religious establishment supported the prime minister in this, it could nudge Iraq toward greater independence from Iran.

Since 2003, Ayatollah Sistani and the religious establishment have largely failed to control the worst tendencies in Iraqi politics. Now the stakes are so high that there is reason to hope for more decisive action. Iraq’s future is in their hands. The margin for error is worryingly small.

Zaid al-Ali was a legal adviser to the United Nations in Iraq from 2005 to 2010, and is the author of “The struggle for Iraq’s future: how corruption, incompetence and sectarianism have undermined democracy”.