Its much-vaunted caliphate has gone, crushed by the might of Russian, Syrian and US warplanes, Iran-backed militias, Kurdish forces and armies launched by Damascus and Baghdad. But while 2017 might have seen the end of Islamic State’s dream of ruling over its twisted vision of an ideal society, the year ended with an ominous sign that its deadly international campaign against the many people and faiths it sees as spiritual foes has gathered new energy.

Last Thursday, dozens of civilians in Kabul were killed in a suicide attack that targeted a Shia cultural centre in the Afghan capital. The assault was the latest in persistent attacks by an affiliate of Isis, which has proved to be resilient despite a relentless campaign against it in recent months.

According to the Isis-linked Amaq news outlet, three blasts were detonated at the compound, which also houses a news agency. A bomber then blew himself up among crowds in the Tebyan cultural centre. At least 41 people were killed and 90 others were injured.

The attack comes despite an intensifying campaign by the US and Afghanistan to uproot the twin threats emanating from Isis and the Taliban, especially since Donald Trump took office in January. Striking inside the Afghan capital, despite the surge in security and military measures, has also raised fears about the enduring ability of the group as the caliphate it once established in Iraq and Syria has collapsed.

In April, the US even dropped the “mother of all bombs” on an Isis base in Afghanistan, an indication of the ferocious campaign against it. But this relentless campaign failed to root it out. In recent months, experts and officials pointed to a successful effort by the Isis affiliate to build roots for itself inside the capital, recruiting dozens of local members, including children.

In Afghanistan, Isis has done so much with so little. In Libya, for example, the group had hundreds of local battle-hardened fighters with experience stretching back to the early years of the Iraq war and who played a pivotal role in early Isis efforts in Syria in 2014, but its fortunes have dwindled over the past two years.

Its territorial demise might exacerbate other insurgencies, if militants fill up the ranks of affiliates in other countries

The Afghanistan affiliate, in contrast, has competition from resurgent Taliban militants who have deeper links to the country, but it has managed to deepen its presence. Striking inside the capital suggests that the group has successfully evolved from a largely foreign-led organisation to an increasingly localised one.

Aside from its persistence in Afghanistan, the nature of Thursday’s attack is a harbinger of what is to come as Isis loses its caliphate in Iraq and Syria. In its statement about the assault, the Isis media outlet claimed that the cultural centre was bankrolled and sponsored by Iran. “The centre is one of the most notable centres for proselytisation to Shiism in Afghanistan,” the statement added. “Young Afghans would be sent to Iran to receive academic studies at the hands of Iranian clerics.”

Isis has sought to tout itself as the defender of Sunnis across the region and the choice of words in its statement is designed to drive that message. The sectarian theme is likely to be the group’s main focus in the coming years, as it retreats from a caliphate to an insurgency. The sectarian narrative helps the group present a “contiguous ideology” from Afghanistan to Syria, in place of the caliphate it seems to have lost; its message to its followers is that the victims of its attack were potential soldiers in the army that Iran is forming everywhere.

Presenting itself as the last line of defence against Iran will ensure that its localised operations have a general regional theme, even as it has lost the global caliphate. This has been a recurrent theme since its rise in 2014, but the group has increasingly focused on sectarianism, not just against the Shia but also against Christians and other religious minorities.

The group’s attack inside Iran in June was designed to achieve this objective and attacks that it portrays as directed against Iranian interests, such as the one in Kabul, serve a similar purpose. By doing so, it seeks to tap into a market in which even al-Qaida and the Taliban cannot compete with the same vigour, as they tend to focus on a relatively less sectarian struggle in their rhetoric. In October, suicide bombers linked to the group killed at least 57 worshippers in a Shia mosque in Kabul. Isis’s sectarian focus makes its persistence even more troubling for the country and the wider region. A day after the Kabul assault, the group also claimed responsibility for a militant shooting on a church in Cairo, killing about a dozen people, one of several attacks targeting Coptic civilians and churches in the country in recent years.

Story continues