The caliphate declared from a pulpit in Mosul three years ago is in tatters, with the remnants of Abu Bakr al-Baghdadi’s forces expelled to the desert and beyond. After nine months of combat, the Iraqi Security Forces have reached both banks of the Tigris River in Mosul, and Iraqi Prime Minister Haider al-Abadi has celebrated victory over ISIS in the country’s second largest city. In the Syrian city of Raqqa, a rebel force heavily supported by the US (on the ground and from the air) have pushed ISIS back into an ever-shrinking enclave. Remorseless airstrikes against ISIS’ sources of revenue – especially oil – and against its leadership have dramatically weakened the group’s ability to sustain and organize its fighters. But ISIS planned for this day. It began fortifying Mosul for the inevitable attack by Iraqi forces as soon as it took the city in June 2014. It came from an underground movement, organized in cells across Sunni parts of Iraq, and will try to revert to life as such. US officials say senior figures in the movement have gone to ground in the Euphrates valley around the city of Deir Ezzor in eastern Syria, the last place where the group is prominent. The fight will continue Before he was killed in a drone strike last year, ISIS spokesman Abu Mohammed al-Adnani said that potential setbacks in Mosul and Raqqa would not spell the group’s end. “No: defeat is losing the will and the desire to fight,” he said. Even as the group’s territory has shrunk, and its all-consuming bureaucracy has collapsed, its ideology endures. To the vast majority of those who have experienced rule under ISIS, it holds no appeal, only memories of terror and hardship. But to some Sunni in both Iraq and Syria, for whom the hated Shia [the Safavid] and the “Crusaders” are existential enemies, the fight will continue. Since its inception, ISIS has prepared for the ‘day after’ the caliphate. Its battle cry has long been “Baqiya wa tatamaddad,” or “remain and expand.” But the battle has always been seen in millennial terms. There is a saying of the Prophet often quoted by ISIS ideologies and followers: “A victorious band of warriors from my followers shall continue to fight for the truth. Despite being deserted and abandoned, they will be at the gates of Jerusalem and its surroundings, they will be at the gates of Damascus and its surroundings…” Read: ISIS’ reign of terror has left a permanent stain on Mosul ISIS prepared for strategy change While its expansion may take generations, the group’s leadership is ready for a stateless Islamic State ‘despite being deserted and abandoned.’ ISIS has cultivated deep roots in Sunni parts of Iraq (less so in Syria where many jihadists regard it as an interloper). Over the past decade, the group has developed networks skilled at raising money, obtaining weapons and clandestine organization across a wide swathe of Iraq – from Diyala in the east to Rutbah close to the Jordanian border. The pattern of recent airstrikes suggests ISIS endures, albeit in a more localized and basic way, in places like Fallujah and Baiji. It has repeatedly shown that it can penetrate security in Baghdad to detonate devastating vehicle bombs. In some ways, it is returning to what it does best – agile attacks, mobility and surprise. As ISIS’ fortunes decline, some militants may try to switch allegiance to other groups. In Syria, these include the former al Qaeda affiliate Jabhat Fateh Al-Sham. But there’s a long history of bad blood between the two groups, which had a bitter and public falling out three years ago. Few in what remains of the ISIS hierarchy would contemplate such a move. In Iraq, there are precious few alternatives for ISIS militants because the group has systematically attacked rivals in the region. Read: What’s next for the city ISIS left in ruins? Opportunities for militants? Even so, ISIS’ decline is an opportunity for al Qaeda in Iraq, Syria and beyond. Terrorism expert Bruce Hoffman suggests some militants will see al Qaeda as the only option for continuing their struggle. ISIS traces its origins to an al Qaeda franchise in Iraq (AQI). It is extraordinarily difficult to estimate how many foreign fighters remain in the region. But losses sustained in Mosul, Raqqa and around Palmyra in Syria would suggest that it’s much lower than the 15,000 estimated by the coalition at the end of 2016. And just a trickle of foreign fighters have been able to reach the “promised land” in the last year than previously. The most worrying possibility for the West is that these foreign fighters, finding survival in Iraq and Syria difficult post-caliphate, might return home to carry out lone-wolf style attacks – as well as recruit new members and revive underground networks. It only takes a handful of individuals to cross the Mediterranean for a European city to be vulnerable to another devastating assault. And while migrant flows through the eastern Mediterranean have been vastly reduced, the exodus from Libya (where ISIS still has a presence) has actually grown. Arrivals in Italy in the first half of this year reached 85,000, a near 20% increase compared to the first six months of 2016. Additionally, it’s unknown how many ISIS members may have already returned to Europe, tasked with carrying on the fight once the caliphate has gone. Turkey, given its proximity to Syria and Iraq and its use as a logistical rear-base by ISIS, may be especially vulnerable. Expansion of ISIS affiliates Rather than risk going home, some ISIS members may try to reach new jihadist pastures. There’s evidence indicating that hundreds have already reached other ISIS-controlled provinces, or wilayats, especially in Libya, which (until last year) appeared to be the leadership’s Plan B. Across the world, from Russia’s North Caucasus to Nigeria, militant groups have pinned their flags to the ISIS banner over the last three years. Some comprise a few dozen men hiding in mountains and jungles; others have been sophisticated and well-funded, with close links to ISIS’ head office. Still others are hardened insurgent groups capable of inflicting heavy casualties on armies, as ISIS’ affiliate in Egypt’s Northern Sinai demonstrated just days ago. Some ISIS fighters now in Syria and Iraq may try to join the Sinai affiliate or travel to Afghanistan, much as al Qaeda fighters moved to Iraq and Yemen after 9/11. They will try to use migrant routes and often will travel alone. But they will take with them skills learned in years of combat. ‘Islamic State’ of mind Perhaps the least predictable among those who make up ISIS 2.0 are the virtual adherents, those radicalized online and nursing a range of grievances who turn to random acts of violence. Two deadly attacks in the US – on an Orlando nightclub and in San Bernardino – fell into this category. As did the truck attack in Nice last year, and smaller ISIS-inspired attacks across Europe. They were carried out by individuals with little understanding of ISIS’ ideology, deep personal grudges and no direct contact with the group’s hierarchy. But that didn’t prevent ISIS from declaring the perpetrators “soldiers of the caliphate.” These individuals, radicalized by what they read and hear, pose a continuing danger. They have few, if any, co-conspirators. They take inspiration from social media sermons and lectures like those of Anwar al-Awlaki, who even since his death has inspired well over a dozen plots in the West. Read: UK authorities offer vacationers advice on how to survive terror Future of ISIS hangs on post-battle plans But whether ISIS, or something similar born from its ashes, survives in its heartland will depend on developments beyond its control. It will depend on how Iraqis of all persuasions handle the “post-conflict” situation, and whether agreement on Syria’s future – with the involvement of Russia and the United States – will suffocate the space in which ISIS thrived. ISIS has shown great skill in exploiting sectarian tensions and terrorizing communities into submission. It is still doing so in parts of Diyala province in Iraq, a long way from Mosul. As analyst Michael Knights has noted, “Without determined sectarian and ethnic peace-building efforts, the identity politics of Diyala will keep the Islamic State and allied movements stocked with recruits in the years to come.” If ISIS is not to regenerate in Mosul, a tinderbox of ethnic and sectarian rivalries, able governance and massive reconstruction will be needed. The Iraqi government doesn’t have a good record in either. There is no agreed plan for running the city, and its Sunni population is wary of the Shia Hash’d militia at its doorstep. The ISIS flag is being torn down in Raqqa, Mosul and points in between. But its ability to inflict terror, take advantage of ungoverned spaces and exploit simmering ethnic and sectarian hatred is far from extinguished.