A member loyal to the Islamic State waves an Islamic State flag in Raqqa, Iraq, June 29, 2014. (Reuters)

Iraqi forces, with heavy U.S. backing, are slowly pushing the Islamic State out of Mosul, the group’s capital in Iraq and the largest city it holds there. Islamic State fighters are fleeing as towns and villages near the city fall. Losing Mosul is only the latest of catastrophes for the Islamic State, whose leaders have sought to rally their troops by reminding them that they survived near-death in 2008 and would do so again: hardly a sign the group is on the march. Indeed, the Islamic State appears to be losing ground everywhere except in the U.S. presidential campaign.

Donald J. Trump, in particular, warns about “a major threat from radical Islamic terrorism,” and tweeted (the forum used for all serious discussions of policy) that “We better get very smart, and very tough, FAST, before it is too late!” He has used the Islamic State menace to club Democrats, claiming Obama has boxed U.S. generals in with a “strategy that is destined to fail.” On Sunday, a few days into the Mosul offensive, Trump tweeted: “The attack on Mosul is turning out to be a total disaster. We gave them months of notice. U.S. is looking so dumb. VOTE TRUMP and WIN AGAIN!” Hillary Clinton, too, regularly discusses the Islamic State, though her rhetoric is far more measured.

Trump has tapped into, and heightened, broader fears about the group. Polls from earlier in 2016 showed that 73 percent of Americans saw the Islamic State as a “very serious” threat to the United States, and another 17 percent saw it as “moderately serious” — a rare issue that crosses political lines. Almost 80 percent believed the Islamic State has assets in the United States and can “launch a major terrorist attack against the U.S. at any time.”

It seems hard to convince most Americans of good news: The Islamic State is hemorrhaging. The group has lost almost half its lands in Iraq and a quarter of what it controlled in Syria, including critical territory along the border with Turkey that was vital for the free flow of foreign fighters — more than 30,000 in all went to Syria to fight with the group. Coalition bombing of its oil assets and the collapse of its tax base as it has lost control of various cities are impoverishing a once-rich group. The flow of foreign fighters, a bellwether, has plummeted: As many as 2,000 recruits crossed over from Turkey per month in 2015; in 2016, this figure is closer to 50.

The Islamic State’s expansion outside Iraq and Syria also is being reversed. Its most promising “province” around the area of Sirte in Libya is now in the hands of pro-government fighters. Instead of trumpeting the Islamic State’s accomplishment, its news organs are conceding the group might lose its territory everywhere. To attract recruits, the group relied heavily on an image of success and the lure of living under a true Islamic government. So military failures are doubly costly: the group loses ground and resources, and it also loses its best recruiting pitches.

The Obama administration and its allies do not deserve all or even most of the credit: The Islamic State is responsible for much of its own undoing. It has warred against Russia, Iran, the Lebanese Hezbollah, the Syrian and Iraqi regimes, France and the United States, among other foes. In contrast to Jabhat Fatah al-Shem, the al-Qaeda branch in Syria, the Islamic State battles other Syrian opposition groups, including fellow Islamic militants, demanding their obedience. While it was working, this “us against the world” inspired zealots everywhere, but the world usually wins such contests in the end.

It is premature to write the Islamic State’s obituary, but it would be ideal if the presidential candidates focused on the hard questions: What to do to keep the Islamic State down and how to stop, or at least contain, conflict in the region? In 2010, back when it was just the Islamic State of Iraq, the group seemed on the verge of defeat. Ordinary Iraqis had turned against the group, and U.S. and Iraqi government forces devastated its ranks. The group held on by abandoning its territorial control, using guerrilla war and terrorism to continue attacks while waiting for its opponents, including the United States, to misstep — which they did. The Islamic State itself has referenced these prior setbacks as it has lost territory, holding up its past resurrection in Iraq as a way to encourage its troops during its current long night. The group’s leaders are preparing for the long haul, and other groups, like Jabhat Fatah al-Shem, may also fill the void.

The United States must also think long-term. Working with local partners, it must prepare for a grinding fight against Islamic State guerrillas and help allies govern the territories they rule. Unfortunately, local states and groups fighting the Islamic State are intensely suspicious of one another. Some are already shooting at each other, and others like the Lebanese Hezbollah or Russia are hardly America’s friends despite their shared aversion to the Islamic militants.

More international terrorism understandably looks like failure, but it should be expected. Whether committed by returning foreign fighters or “lone wolves,” terrorism is all the more likely because the Islamic State itself is trying to internationalize the conflict. Since the group strives to maintain an image of success, high-profile operations in the West can compensate for territorial losses. Earlier this year, its spokesman and external operations leader Abu Muhammad al-Adnani (recently killed by a U.S. airstrike) declared, “The smallest action you do in the heart of their land is dearer to us than the largest action by us and more effective and more damaging to them.”  Foreign fighters may also flee the caliphate for Lebanon or other neighboring states, bringing more violence in their wake.

For all the U.S. successes against the Islamic State, its biggest counterterrorism failure is resilience. Despite relatively few deaths since 9/11, Americans’ fear of terrorism has not diminished. Unfortunately, when politicians like Trump play up the threat it exaggerates the impact of even small attacks, making the Islamic State seem more powerful than it is.