FOR months Iraqis were told that Islamic State (IS) was on the way out. In April Haider al-Abadi, the prime minister, declared he had won the “psychological battle” after chasing the jihadists from Tikrit, Saddam Hussein’s old hometown. Baghdad residents played pop songs mocking IS on their car radios. But Ramadi’s fall on May 15th has punctured that optimism, and the streets are again filled with foreboding. IS is only a short drive away, and also menaces the oil refinery and power plant at Baiji on which Baghdad depends. The news five days later that IS had seized Palmyra, in Syria, heightened the alarm.

Ramadi, some 110km (70 miles) west of Baghdad, is the capital of Anbar, Iraq’s largest province, and was the last remaining city held by the government in the Sunni-dominated region. IS had occupied parts of the sprawling city for many months, but retaining control of government buildings there was a key part of plans to reconquer the province. In the event, the Iraqi army fared no better than when it fled Mosul, Iraq’s second city, last June, again leaving large quantities of military hardware behind. A wave of suicide trucks punched through Ramadi’s defences, and sent the men who held them running.

After almost a year of American-led bombardment and Iranian-backed ground operations, IS appears unbowed. It has suffered reverses and has lost territory to the Kurds as well as to the Baghdad government and its militias. It has seen some of its commanders, including its deputy leader, killed by American bombs. Air raids have wrecked oil installations it controls, slashing its revenues.

But IS still continues to attract foreign and local fighters. Its deployment of convoys of suicide bombers in 15-tonne trucks renders futile attempts to hold fortified lines. It is pushing forward again in Anbar, the heartland of Iraq’s Sunni tribes, and therefore fertile ground for IS, which has drawn much of its support from Sunnis fearful of and marginalised by the Shia-dominated government in Baghdad. And it is also gaining ground again in Syria, on May 20th storming Palmyra. The fear is that it will destroy the site of one of the world’s treasures, a Roman-era city, as it has done to other pre-Muslim antiquities.

It is easy to blame Mr Abadi for the Ramadi debacle. But the government’s problems are far bigger than the choice of prime minister. Its army is a paper tiger, with commanders who inflate their ranks with ghost soldiers and claim the extra salaries, but who flee when in danger. The mostly Shia rank-and-file soldiers follow their lead, terrified of capture by a ruthless foe that views them as heretics. After overrunning Tikrit last June, IS butchered 1,500 army cadets at Camp Speicher.

Unable to depend on his own forces, Mr Abadi has turned to the Hashid al-Shabi, or “popular mobilisation units”, unleashed last June to prevent IS sweeping into Baghdad. These are a conglomeration of some 40 militias, almost exclusively Shia and many backed by Iran. Over the past year, they have pushed IS back from the Iranian border and cleared a belt around Baghdad. They are now preparing, along with the Iraqi army, to launch a counter-assault on Ramadi. But the Hashid al-Shabi could prove a double-edged sword. If the Shia militias lose, they weaken Baghdad’s best defence. If they win, they may challenge the government for control. Whatever the case, their deployment in Sunni areas risks sparking fresh sectarian bloodletting.

An interactive guide to the Middle East's tangled conflicts Instead, the Americans and Iraq’s Sunni neighbours have encouraged Mr Abadi to arm the Sunni tribes, though so far to little effect. They recall the “Sunni Awakening” of 2006-7 when America’s commanders paid, trained and armed Anbar’s tribesmen, and within seven months pushed IS’s precursors, al-Qaeda in Iraq, out of the province. But the trick will be hard to repeat. The province’s 13 main tribes are as divided as they are weak. Concerned outsiders look on but would rather pass the buck. Jordan is helping the Americans train a small number of Sunni tribesmen but wants the Iraqi government to pay for a proper roll-out. Saudi Arabia is preoccupied with its war in Yemen. America continues to train Sunni soldiers at its Ain al-Asad base deep in Anbar, but pending their deployment has welcomed the militia’s intervention, apparently hopeful that the Shia units will succeed where the Iraqi army and the coalition have failed. Putting any more American troops, beyond a few thousand advisers and trainers, on the ground, risks dragging the United States back into ground combat.