Ten days after the United States carried out its first airstrike on Aug. 8 against the Islamic State on Iraqi territory, government forces regained control of the biggest dam in the country, near Mosul, the country’s second city. A ferocious al-Qaida-inspired jihadist group that controls swathes of territory in Syria and Iraq and wants to turn the entire region into a caliphate, the Islamic State looks as if it is at last on the defensive in northern Iraq.

Thanks to a series of U.S. air raids, Kurdish and Iraqi forces scattered Islamic State fighters who had hoisted their black flags on the walls of the great dam. The Iraqi government in Baghdad hailed the event. The Iraqi Kurds in their capital, Irbil, posted photographs of their peshmerga forces lording it over the turquoise lake. President Barack Obama cited the recovery of the dam as “important progress.”

With American aerial help and the advice of nearly 400 American advisers on the ground, Iraq’s government forces and the Kurdish peshmerga have made gains elsewhere, too. Most of the tens of thousands of Yazidis stranded on Sinjar mountain since the Islamic State raided their towns at the start of August have been carried to safety. Irbil is secure. The Americans, who have now carried out at least 60 air raids on the Islamic State, have revived the morale of the Iraqi government forces, who fell apart at the start of the jihadist offensive in June. On Tuesday, Iraq’s army said it had started a campaign to recapture Tikrit, Saddam Hussein’s hometown, which lies about 112 miles northwest of Baghdad.

But the Islamic State is far from contained, let alone defeated. It continues to massacre people belonging to non-Sunni sects in a string of villages around Mosul, which it captured in June, and along the border with Kurdistan. In Tikrit it may be beating back the government’s forces. It still holds a slew of towns in Anbar province and along the Euphrates river on both sides of the border with Syria. Even hitherto anti-American Iraqis, such as Hakim al-Zamili, a parliamentarian from Muqtada al-Sadr’s populist Shia movement, want the Americans to increase their air attacks on the Islamic State.

More significantly, the Islamic State has been consolidating its grip over large chunks of northern and eastern Syria, and has been gaining ground against moderate rebel Syrian groups opposed both to Bashar Assad’s regime and to the Islamic State. Though the Americans say their strikes have hurt the Islamic State badly, the group is still expanding its membership. The vast majority of the world’s 1.6 billion Muslims reject the group’s claim to speak for them, but it is increasingly popular among global jihadists.

Hundreds of recruits are thought to have joined since June, when a caliphate was declared, many of them from countries outside Iraq and Syria. New groups claiming to be cells of the Islamic State have popped up recently as far away as Morocco. This month an Islamic State unit made a foray into Lebanon. With fresh acquisitions of land, oil fields, cash and global support, it is trying to consolidate its rule in Syria, while performing the functions of a state in such towns as Raqqa and Deir ez-Zor.

Moreover, the Islamic State presents a threat beyond Iraq and Syria.

“First, they may not be imminent but it’s only a matter of time before transnational operations are launched,” said Fred Hof, a former State Department man now at the Atlantic Council, a Washington think tank. “Second, nationals who return home pose a threat.”

On Aug. 15, the United Nations passed a resolution backing sanctions on anyone recruiting, financing or fighting for the Islamic State, or supplying it with weapons. Two days later David Cameron, Britain’s prime minister, wrote of the danger the Islamic State posed “on the streets” of his country. Pope Francis spoke out against the group, too, calling for it to be “stopped,” implying even by force.

In retaliation for America’s recent intervention in Iraq, the Islamic State put out a video on Tuesday showing one of its members, thought to be British, beheading an American journalist, James Foley, who had been captured in Syria in 2012. (It emerged that U.S. Special Forces, in their first known raid on Syrian soil, had earlier failed to rescue him.) The Islamic State is threatening to kill a second journalist it is holding.

The battle against the Islamic State will not be won by military means alone. In that respect, the agreement on Aug. 14 by Nouri al-Maliki, a sectarian-minded Shia, to step down after eight years as Iraq’s prime minister, opens the way under his replacement, Haider al-Abadi, to a more inclusive Iraqi government. It might draw away disgruntled Iraqi Sunnis from the Islamic State’s embrace.

Sunnis in Baghdad say that al-Abadi, if he is to win them over, must seek to amend the de-Baathification and anti-terrorism laws that al-Maliki abused to crack down on them. He must also free thousands of Sunni prisoners and give more powers to local politicians. Sunni tribal leaders insist that they could kick out the Islamic State in a flash. But Sunnis must first be persuaded that the government in Baghdad is giving them a fair deal.

Since the Islamic State turned its guns on Iraq’s Kurds, many of their leaders have softened their demands for outright, immediate independence. But they want the government in Baghdad to cede the disputed territories taken by them since the Iraqi army fled in the face of the IS onslaught. The Kurds also want a deal over oil and gas in their area. Ibrahim Bahr al-Uloum, a senior Shia member of parliament familiar with negotiations for a new government, said the “biggest demand” of Sunnis and Kurds is for “real participation in political and security decision-making — and this can be agreed on.” But al-Abadi will have to hurry.

If the war against the Islamic State in Iraq can be won, the struggle in Syria could be more fraught. Even though it has less support there, it is well entrenched in parts of the country. Since January, groups of more moderate Sunni rebels in Syria have been fighting a desperate two-pronged war, against both Assad’s forces and against the Islamic State. In recent days the Islamic State has advanced against the few bases still held by the regime in the east, taking four in as many weeks. Around Aleppo it has captured at least a dozen villages and is now besieging Marea, a nearby town long held by the moderate rebels, who are in increasing danger of being snuffed out.

Assad has previously tended to leave the Islamic State alone, happy to let it hurt the more moderate rebels. But recently his air force has struck the group’s base in Raqqa. The Americans have so far decided that they cannot do likewise, deeming that they must not be seen to operate on the same side as the man whose overthrow they have repeatedly demanded.

But they may be persuaded to change their mind if the most influential governments in the region, including Saudi Arabia, Egypt, Turkey and even Iran, were able in joint or parallel statements to endorse the bombing of the Islamic State in Syria — or at least to abstain from opposing it. So far the West has lacked a policy that spans national borders. Yet Hof points out that the Islamic State “is a problem that transcends national boundaries and has to be approached as a problem that transcends nationalist boundaries.”

From the Economist magazine.