THEY said it would be over by Christmas. Now Haider al-Abadi, Iraq’s prime minister, is suggesting that the battle for Mosul could last until Easter. For almost a month his forces had stalled on what was supposed to be the easier eastern bank of Iraq’s second city. And the costs have been gruelling. A fifth of Iraq’s elite force has reportedly fallen in the assault. With the support of more American special forces, Mr Abadi has launched a second phase, taking the city’s industrial zone. Progress is being made. But what Iraqi soldiers clear by day, Islamic State (IS) fighters often regain by night, thanks to a warren of tunnels under the front lines. Not only are IS fighters holding the line against Iraqi soldiers and their American backers after ten weeks of fighting in Mosul, but they are also fending off Turkish troops 515km (320 miles) to the west, around the town of al-Bab in northern Syria. They have also recaptured Palmyra from the Syrian regime.

Across Iraq the insurgency has a new lease of life. The sickening rhythm of suicide bombs in Shia suburbs of Baghdad and southern Iraq is quickening again. In Anbar and Salahuddin, provinces long since reclaimed by the government, IS is also flexing its muscles. On January 2nd it won control of a police station in Samarra for several hours and it cut briefly the Baghdad to Mosul road. It is putting out lights in Diyala. “It is not an organisation that is close to collapse,” says an analyst in touch with people in Mosul.

The prolonged campaign carries political costs for Mr Abadi, who had sought to turn himself from a bumbling office-holder into a victorious commander by donning military fatigues. Should there be further mishaps, Mr Abadi’s rivals in Baghdad will be waiting to pounce. Among them is his predecessor, Nouri al-Maliki, and his cohorts in Iraq’s assortment of predominantly Shia militias, which are collectively known as the Hashd al-Shaabi, or popular mobilisation forces (PMF). As the government-led advance on Mosul slows, they are calling for the deployment of Iranian-backed brigades. So short of men are Iraq’s army and police that even some American commanders now welcome the use of these auxiliaries.

To date the Iraqi government’s assault (with air support from the American-led coalition) has managed to minimise civilian casualties in Mosul. But if Shia militias are unleashed another bout of sectarian killings might ensue. It could push the city’s remaining 900,000 Sunnis towards IS. Moreover an enhanced role for the militias would weaken the state by boosting the PMF. Its brigades already display factional flags, run several secret prisons and raise money by extorting bribes at gunpoint at checkpoints.

Mr Maliki, for his part, seems to be intent on building a sectarian pasdaran, or revolutionary guard, much like the one that wields real power in neighbouring Iran. As prime minister from 2006 to 2014 Mr Maliki built up networks that still give him influence. From the judiciary to the civil service to parliament, many in Iraq’s upper echelons owe him their positions. One of his last acts as prime minister was to form the PMF. Having tried for months to chip away at Mr Abadi’s authority by impeaching his senior ministers, Mr Maliki has recently switched tack in favour of bolstering the PMF. On November 26th MPs voted to create an autonomous force comprising 110,000 PMF militiamen paid by the government and overseen by parliament.

In response Mr Abadi is using the new PMF law to woo the Sunni militias that Mr Maliki had ostracised when he was prime minister. He has brought thousands of Sunni officers and soldiers from Saddam Hussein’s former army onto the government payroll under the command of a former governor of Mosul, Atheel al-Nujaifi. Charges of terrorism against Khamis al-Khanjar, a Sunni politician financed by the Gulf, have been quietly dropped. And with Mr Abadi’s blessing, Ammar al-Hakim, who heads the largest Shia parliamentary bloc, has gone to Amman and Beirut to negotiate terms for a national reconciliation, including an amnesty, with Sunni exiles who had long since despaired of a deal with Baghdad’s Shia masters.

The hope is that if they are promised a future inside Iraq, former Baathists and other Sunni Islamists might join forces to rid Iraq of IS. “Some Shia are starting to realise that if they can’t absorb Sunnis and Kurds, what remains of Iraq risks becoming another wilaya [province]of Iran,” says a diplomat in Baghdad.

Mr Abadi’s main failure has been political: he has not broken the hold that sectarian parties, including his own, have on Iraq’s coffers. Political parties in his cabinet continue to take handsome cuts from government contracts and collect the pay of ghost workers in defunct factories. Rather than tackling political corruption, he has squandered the backing of protesters and Iraq’s leading ayatollahs by slashing the pay of civil servants and raising taxes.

Yet for all his setbacks, Mr Abadi has regained most of the territory that Mr Maliki had lost. He has secured renewed American military support and overseen a four-fold increase in America’s troop deployment over the past year. With American help, the panic-stricken army that fled Mosul in June 2014 has been rearmed and now sports an air force and a division of special-forces soldiers who are proving capable fighters. His men are also operating alongside Kurdish fighters for the first time in a decade.

Socially, too, Baghdad is regaining a semblance of normality. The concrete barricades encasing public buildings like lugubrious tombstones have slowly come down, and checkpoints have thinned. Iraq’s economy is now weathering a crisis caused by a slump in the oil price and a surge in war-related spending. Oil production reached record levels in 2016 and the IMF has extended a $5.3bn loan, which promises to attract an additional $11bn in international credit and export guarantees. The bits of the economy not related to oil, which slumped 5% in 2016 and 14% the year before, will probably expand by 5% this year, the IMF reckons. American companies that had previously fled as Iraq slipped into mayhem, such as General Electric, are now tiptoeing back.

Even in parliament unusual alliances are forming across sectarian lines. Kurds, Sunni Arabs and Shias no longer vote as united blocs. Selim Jabbouri, the Sunni parliamentary speaker who hails from the Muslim Brotherhood, speaks of establishing a cross-confessional party in the 2018 elections and canvasses in Shia as well as Sunni parts of Iraq. For all its faults, Iraq is still the Arab world’s most boisterous multiparty democracy. Perhaps it may after all convince a majority of its people that they have a future together.