The last fighters are holding out, just. The leader, Abu Bakr al-Baghdadi, is still alive but hiding somewhere in the desert. We have already had one “final defeat” of Islamic State. This came 18 months ago when the organisation’s capital, Raqqa, fell. Once, it held territory the size of the UK; now, it holds a square kilometre of the remote town of Baghouz in eastern Syria. Soon, it will no longer hold even that.

There is a strong argument for caution before anyone talks of “mission accomplished”. Many of the circumstances that favoured the rise of the organisation remain. In Iraq, these include the weakness of the state and security forces, the dominance of the Shia majority and the shortsightedness of its leaders, as well as the alienation and marginalisation of the Iraqi Sunni minority, long the extremists’ core constituency. Deeply rooted criminal networks don’t help, nor does the legacy of radicalisation and brutalisation of decades of violence. Syria remains an anarchic battleground of factions, militia and forces, where powers great and small, near and far, still seek advantage. So it should be no surprise that recent attacks in Iraq suggest that a new Isis-led insurgent campaign is well under way.

However, it would be wrong not to see a victory as a victory. If we put the rise and fall of Isis in a broader geographic and historic context, it shows us the fundamental failings of Islamic militancy, not its enduring strength.

First, Islamic militant groups need a narrative. Isis drew young men, and some young women, from Europe and from across the Islamic world because it was audacious, new and apparently successful. In 2015, when the group was at the peak of its power, a former militant (and delinquent) in Belgium described Isis to me as the “baddest gang around”. It isn’t any longer. Loyalists have already tried to frame the failure of the caliphate as a test sent by God for the faithful, arguing that the path to salvation is never smooth, or that at least Isis tried, which is more than any other militant group has done in living memory. But in 2004, Abu Anas al-Shami, the in-house religious adviser of the group that evolved into Isis, complained that he and fellow members did not “even have a place to roll out their prayer mats”, such was their weakness. They don’t now either.

Shamima Begum left Britain to join Isis when she was 15. She now wants to return. Photograph: Metropolitan Police/PA

The contrast with another conflict that attracted tens of thousands of foreigners to fight as “mujahideen” is instructive. The idea that al-Qaida and its legion of Arabs won the war in Afghanistan against the Soviets in the 1980s is entirely without basis. The contribution of overseas fighters during the conflict was militarily negligible and al-Qaida was founded at the conflict’s end. But this myth has been enormously important in motivating militants across the Islamic world ever since. It is very hard to see the story of the Isis caliphate playing a similar role. Al-Qaida still exists, of course. Its charismatic leader, Osama bin Laden, survived on the run for a decade before being shot dead by US special forces in his hideout in Pakistan in 2011. It is unlikely that al-Baghdadi will hold out for as long, given the terrain and the enmity of all the local actors.

Many point to the toxic ideas of Isis as being its most dangerous legacy. Of course ideology is important, yet the last four decades of Islamic militancy have shown that, without territory, the threat extremists can pose to the west is extremely limited and can usually be contained locally, albeit at an often high cost in human suffering. Without a haven in Afghanistan, al-Qaida could never have organised and executed the 9/11 attacks of 2001. Without its Syrian infrastructure, Isis could not have launched its wave of violence in Europe between 2014 and 2016.

Both groups needed western recruits for such operations. Even if they could make the difficult journey to Syria or Iraq, what would western or, for that matter, Tunisian, Egyptian or Indonesian recruits now find? Certainly not the “five-star jihad” they enjoyed before, with internet cafes, salaries, companions from similar backgrounds and relatively comfortable accommodation. The prospect of a very uncomfortable – and probably very short – time in hideouts somewhere in the upper Euphrates valley is hardly attractive. As the story of Shamima Begum shows, the direction of travel is from east to west, not west to east.

All this poses a fundamental problem for the militants that they have yet to overcome. Without a territorial base, extremist groups such as al-Qaida or Isis cannot realise their project to build a new “Islamic community” or to confront “hypocrite, apostate” local powers and their backers in the west. But any effort to establish a territorial base makes them extremely vulnerable. Any attacks launched from their new territories will eventually provoke well-armed and powerful enemies who will seek their nascent state’s destruction and, history tells us, will probably succeed.

Even if the new state’s leaders postpone any offensive against external foes, internal contradictions will eventually lead to the project’s collapse too. The caliphate’s coercive state model relied on continual expansion. Once the forward momentum slowed and there were no new human or economic resources to exploit, stagnation was inevitable. Local communities and power-brokers wavered and fell away. Stagnation led to retreat, then to rout. At the very end, the only ones left were those with nowhere else to go. And even some of these appear to have launched a bid to kill al-Baghdadi before the final destruction of his organisation as we now know it. To foment fitna, or division and strife, is a terrible wrong to the ummah, the community of Muslims, yet it is endemic among extremists.

Islamic militants have spent the best part of half a century in acrimonious argument over different ways of overcoming these problems. In the west, we tend to dismiss these debates as esoteric internal squabbles. They are not. We should certainly be aware of the strengths of Islamic militancy, and of the threat it poses, but we should also recognise its weaknesses when we see them.

• Jason Burke is the author of The New Threat: The Past, Present and Future of Islamic Militancy