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, also known as ISIS-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 U.S. soldiers, as American troops evacuated in August.
Here is a look at the rivalry between the two groups:
What is IS-Khorasan?
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 the Foundation for Strategic Research, a French think tank, describes IS-Khorasan as "a conglomeration of former jihadist organizations, including Uyghurs and Uzbeks, and Taliban defectors."
According to U.N. estimates, IS-Khorasan 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 reputedly been led by 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 rumored to have been an al-Qaida 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-Khorasan 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 U.S.-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, al-Muhajir placed "a renewed emphasis on urban warfare and symbolic violence."
Where did the rivalry begin?
Many IS-Khorasan fighters fought for the Taliban or allied groups, or came from insurgent movements inspired by al-Qaida.
While both the Taliban and IS-Khorasan 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-Khorasan, however, remains bent on eradicating groups it considers apostates.
The Taliban of 2021 aim to rule Afghanistan under their interpretation of Islamic law, whereas IS-Khorasan 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.
"ISIS-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-Khorasan] will try to capitalize."
Are the Taliban equipped to fight back?
Afghanistan's ousted U.S.-backed government received hundreds of billions of dollars in support and security assistance but could defeat neither the Taliban nor IS-Khorasan.
Now the Taliban face IS-Khorasan 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-Khorasan cell in Kabul after a suicide attack.
And they have the potential support of two groups that know IS-Khorasan's tactics very well.
As a report from the U.S.-based Soufan Center said, if the Taliban are to fight ISIS-K, they will have to "rely on the Haqqani network, al-Qaida and other violent nonstate actors for manpower, combat expertise and logistical support."