As the Taliban shift their focus from insurgency to government, their most formidable rival is the Islamic State's regional chapter, which has staged a string of bloody attacks in recent weeks.
The latest atrocity claimed by Islamic State-Khorasan (IS-K) killed at least 19 people Tuesday, including a senior Taliban commander at a military hospital in Kabul, with dozens more wounded.
It followed the slaughter of scores of Shiite Muslims at a mosque last month, and a suicide bombing that killed more than 100 people including 13 US soldiers as American troops evacuated in August.
Here is a look at the rivalry between the two groups:
- What is IS-K? -
The Islamic State group came to prominence when it proclaimed a "caliphate" in Syria in 2014.
It inspired a number of offshoots elsewhere including in "Khorasan", a historical region taking in parts of modern day Afghanistan, Iran, Pakistan and Turkmenistan.
Jean-Luc Marret, of French think tank the Foundation for Strategic Research, describes IS-K as "a conglomeration of former jihadist organisations, including Uyghurs and Uzbeks, and Taliban defectors".
According to UN estimates, IS-K has between 500 and a few thousand fighters in northern and eastern Afghanistan, including cells under the nose of the Taliban in the capital Kabul.
Since 2020, the group has been reputedly led by one Shahab al-Muhajir, whose nom de guerre suggests he arrived in the region from the Arab world but his origins remain murky.
He is variously rumoured to have been an Al-Qaeda commander or a former member of the Haqqani network, one of the most powerful and feared factions in the Taliban.
- How great is the threat? -
IS-K has been responsible for some of the deadliest attacks in the region in recent years, massacring civilians in Afghanistan and Pakistan, at mosques, shrines, public squares and even hospitals.
The group has especially targeted Muslims from sects it considers heretical, including Shiites -- much like the original IS group.
It was hit hard by both the Taliban and US-led forces and was losing influence but its attacks have ramped up since their rival Islamists took power in August.
According to researcher Abdul Sayed of online extremism tracker ExTrac, Shahad placed "a renewed emphasis on urban warfare and symbolic violence".
- Where did the rivalry begin? -
Many IS-K fighters fought for the Taliban or allied groups, or came from insurgent movements inspired by Al-Qaeda.
While both the Taliban and IS-K are hardline Sunni Islamist militants, they differ on strategy and interpretation of religion, while claiming to be the true flag-bearers of jihad.
Despite a history of targeting Shiites, the Taliban have now pledged to protect them. IS-K, however, remains bent on eradicating groups it considers "apostates".
The Taliban of 2021 aim to rule Afghanistan unde their interpretation of Islamic law, whereas IS-K is still wedded to the goal of a global "caliphate".
While differences run deep, the border between the groups is porous, and fighters can shift sides as their commanders' views and opportunities evolve.
"IS-K has been previously successful in recruiting members disaffected with the Taliban and those who perceive the Taliban as too moderate," said Barbara Kelemen, of Dragonfly Security Intelligence.
"With the Taliban now seemingly implementing some moderate reforms... there is a high probability (IS-K) will try to capitalise."
- Are the Taliban equipped to fight back? -
Afghanistan's ousted US-backed government received hundreds of billions of dollars in support and security assistance but could defeat neither the Taliban nor IS-K.
Now the Taliban face IS-K with very little outside assistance, and none of the sophisticated intelligence gathering and surveillance deployed by foreign militaries.
They know their enemy and the terrain though, and last month announced the destruction of an IS-K cell in Kabul after a suicide attack.
And they have the potential support of two groups that know IS-K's tactics very well.
As a report from the US-based Soufan Centre explained: "To combat IS-K, the Taliban is going to rely on the Haqqani network, Al-Qaeda, and other violent non-state actors for manpower, combat expertise, and logistical support."