Iraqi forces are stalled and suffering heavy casualties in their assault on the last Isis fighters defending close-packed buildings in the Old City of Mosul. Civilian loss of life is very high as US aircraft, Iraqi helicopters and artillery, try to target Isis strongpoints in a small area in which at least 300,000 civilians are trapped and unable to reach safety.

Isis fighters shoot at government troops from houses and then escape quickly through holes they have ordered people to cut in the walls of their homes, leaving them to face retaliatory fire. In a single district of Mosul this week 237 civilians were killed by air strikes, including 120 of them in one house, according to a Kurdish news agency.

The last chapter of the siege of Mosul, which has now been going on for 155 days, is likely to be more bloody than anything seen before. It will certainly end with the capture of the city or what is left of it, raising the crucial question of how far its loss will be a death blow to Isis.

It was the unexpected seizure of Mosul by a few thousand Isis fighters in June 2014 after defeating an Iraqi government garrison 20 times as large, that turned the fundamentalist movement into an international force. At its peak, the self-declared Caliphate ruled an area in northern Iraq and eastern Syria as large as Great Britain.

Isis had always used terrorism directed against civilians as an integral part of its tactics to show strength, spread fear and dominate the news agenda. Its atrocities – scarcely noticed outside Iraq before the fall of Mosul – have always been primarily directed against Shia victims, blown apart as they shopped in markets or took part in pilgrimages. It was only after the intervention of foreign powers in 2014 and 2015 that Isis extended it terrorist campaign outside Iraq and Syria.

There is a thin but definite line connecting what happened in Mosul two and a half years ago and the impulse that led Khalid Masood to carry out his deadly rampage in Westminster this week. In Iraq and Syria, Isis knew that it had to slaughter thousands to spread terror, but in cities like London, Nice, Berlin, Paris and Brussels much smaller attacks would have similar impact. All that was needed was one or more fanatical individuals willing to get killed as a testimony to their faith.

It is this willingness to die for a grotesque belief which has enabled Isis and al-Qaeda to wield so much power from the Tigris to the Thames, well beyond what could be expected from relatively small organisations. In conventional warfare, suicide attacks have enabled them to fight armies equipped with aircraft, tanks and artillery. “I cannot think of a single successful armed opposition offensive in Syria which was not led by suicide bombers,” a military expert told me in Damascus last year. This article is being written in Irbil 50 miles east of Mosul where there were no less than 600 attacks by men driving vehicles packed with explosives in the first six weeks of the Iraqi government offensive that began on 17 October last year.

There is no doubt that the fall of Mosul will weaken Isis, but the extent and permanence of this weakness is uncertain. Isis portrayed its victories in 2014 as a sign of divine intervention on its behalf and used this as a powerful argument to win adherents. But this claim becomes counter-effective when victory on the battlefield is replaced by defeat. The Caliphate today, battered from a dozen directions, no longer looks anything like the Islamic utopia its founders were claiming to establish and was to serve as a model society for Muslims across the world.

The military defeat of Isis in Mosul, combined with the likely loss of its de facto Syrian capital at Raqqa later this year, means that the movement will no longer control a quasi-state more powerful than many members of the UN. At its peak, the Caliphate not only had strong armies but an effective state machine that levied taxes and controlled the lives of five or six million people. Through its propaganda, money and expertise, it could motivate and, to a degree, organise cells and individuals to carry out terrorist acts internationally. As its last urban centres fall and its territories fragment its ability to project its power is much reduced.

But Isis is not going to go entirely out of business and one should not underestimate its capacity to survive. It did so before against the odds in Iraq after 2006, when the surge in US troop numbers and the defection of many Sunni Arab tribes, appeared to have all but eliminated it. At the end of the day it is a sect dependent on a core of true believers and not a regular army whose organisation, once disrupted, cannot be easily rebuilt.

Isis commanders are experienced soldiers who fought as guerrillas before 2014 and can do so again. Moreover, they must always have known that from a military point of view, Mosul was indefensible because of the massive firepower of the US-led air coalition supporting Iraqi ground forces. The same is true in Syria where Isis is fighting the Kurds, backed by the US, and the Syrian army, backed by Russia.

There are already signs that Isis commanders can see the writing on the wall and are moving fighters back into areas outside Mosul north and west of Baghdad where they will fight on. The same process is likely to happen in Syria where Isis is being battered by a myriad of enemies, who do not like each other much but will probably hang together until Isis is defeated.

ORDER IT NOW

The total elimination of Isis and al-Qaeda type movements in Iraq and Syria depends whether the wars that have torn apart these two countries are coming to an end. Isis and the al-Qaeda clones grew out of the chaos of war in both countries. They also relied on the toleration or covert support of Sunni states like Turkey, Saudi Arabia and Qatar in their early growth period. Without such backing they will have difficulty in doing more than harrying Iraqi and Syrian government forces.

We are seeing the end of Isis in Iraq and Syria as a force powerful enough to threaten established governments in Baghdad and Damascus as it was capable of doing less than three years ago. It is still able to inspire individuals like Khalid Masood to make high-profile terrorist attacks which dominate the headlines for days on end, but they do not seem to have a cell structure in place in Europe to carry out more wide ranging attacks. A purpose of the attention-grabbing atrocities carried out by Isis supporters in capital cities is to give an exaggerated impression of the movement’s strength outside its core areas.

Isis is facing battlefield reverses in Iraq and Syria that will make it more and more difficult for it to inspire individuals abroad to kill and to die for its monstrous version of Islam. If peace now returns to the region then these defeats are likely to prove permanent.