IT HAS been a long time in coming. But on December 27th Iraq’s security forces announced they had recaptured the city of Ramadi from Islamic State (IS), with only pockets of resistance remaining. This followed a week of heavy fighting by the Iraqi army, local police and Sunni tribal fighters, all backed by American air strikes.

The expulsion of jihadists from the capital of Anbar, a mainly Sunni province, is a morale-boosting victory for the beleaguered government of Haider al-Abadi in Baghdad. It will go some way towards expunging the memory of the humiliating flight of the army from the city seven months ago, when a numerically inferior IS force launched a stunning assault, spearheaded by at least 30 vehicular suicide-bombs, some of them armoured bulldozers packing enough explosive to demolish entire streets. Outflanked and outgunned, even the army’s Golden Division, a highly regarded American-trained special-forces unit, succumbed to panic.

The carefully orchestrated campaign to recover Ramadi, which saw much closer co-ordination between troops on the ground and coalition air power than in the past, is an indication of how other battles to expel IS from Iraqi cities may be conducted. Air strikes are claimed to have killed at least 350 IS fighters in the days before the ground offensive began in earnest.

While it is true that Iraqi forces some 10,000 strong were needed to defeat no more than 1,000 IS fighters, the difficulties should not be underestimated. IS had time to construct a multilayered defence based on booby traps and a network of tunnels that allowed shooters and suicide-bombers to move around the town unseen by surveillance drones. The Iraqi army had to spend months encircling the city and slowly cutting IS off from outside help. This allowed Iraqi units to move cautiously into the ruined city, street by street.

Significantly, Iranian-backed Shia militias, who have often been in the vanguard of the fight against IS during the past 18 months, were largely excluded from the battle. This was at the insistence of the Americans, who want to encourage a Sunni uprising against IS, like the one they fomented against its predecessor, al-Qaeda in Iraq, in 2006. But the results have been patchy, because the promised supply of American weapons to Anbari Sunni tribes has been blocked by the predominantly Shia government in Baghdad.

Next stop, Fallujah

Given the deep sectarian divisions, limiting the role of the Shia “Popular Mobilisation Forces” in Anbar remains a priority for the Americans. Most are backed and financed by Iran—and Mr Abadi has little influence over such groups.

If the government is to build on its success in Ramadi, it must show displaced Sunni inhabitants that it can both hold the city and start rebuilding it. That means providing material support for the Sunni tribes and local police to garrison Ramadi, while freeing up the overstretched Iraqi army to take on IS elsewhere in Anbar. The jihadists still control not only Fallujah, but also Ana, Rawa, Hit and al-Qaim, towns which between them have (or had) a population of over 700,000.

The Iraqi army will have little choice but to work with the Shia militias in the continuing attempt to recapture Fallujah, which has seen only intermittent progress in the past year. The tactics used in Ramadi—encirclement and air strikes—are being applied to the city, which is now more or less completely cut off. But Fallujah, which was al-Qaeda in Iraq’s first stronghold and the scene of bitter fighting with American troops in 2004, will be much harder to crack.

Mr Abadi promised on December 28th that IS will be driven from his country by the end of 2016. “We are coming to liberate Mosul, which will be the fatal blow to [IS],” he said. A concerted attempt to retake Iraq’s second city (seized by IS 18 months ago) does now appear more likely, although it will have to wait until Fallujah is restored to government control and the Iraqi army can field more effective units to join with Kurdish Peshmerga fighters.

Estimates differ as to how many IS combatants there are in Mosul. IS says it has 30,000. Iraqi government sources put the number at a more modest 1,500. But IS has had a long time to dig itself in to the northern city, and at least some of the people there are said to prefer the so-called caliphate, for all its brutality, to rule from Baghdad. Mosul is a huge source of funding for IS, because it has so many people for the jihadists to tax. If it should fall, IS’s pretensions to being a state will fall with it. But there is still quite a way to go.