Hours later, the Islamic State claimed responsibility for the attack, issuing a bulletin on its Amaq news agency. The statement was disseminated on the messaging app Telegram, where members and followers congregate in secret channels, or chat rooms.

Although the Islamic State has lost nearly all of its former strongholds in Iraq and Syria, the threat that the group poses to the rest of the world has not abated, and in some parts of the world it has increased. The Islamic State, also known as ISIS or ISIL, has caused more casualties in Kabul than the Taliban, and in Yemen, the number of the group’s fighters has doubled in the past year, according to the United States military. In recent months, the group also carried out what officials called the deadliest terrorist attack in modern Egyptian history, which took the lives of more than 300 people at a Sufi mosque.

The Islamic State affiliate in Afghanistan, which first emerged in the eastern part of the country in 2014, has increasingly carried out deadly attacks in Kabul. Last week, the group claimed an attack on a Shiite cultural center in western Kabul that left at least 40 people dead and dozens wounded.

While the group has faced intense pressure from Afghan commandos and American airstrikes in its foothold in Nangarhar Province, officials have struggled to gain a clear understanding of the urban cells behind the latest spate of attacks claimed by the group. In the past, many of the urban attacks in places like Kabul were carried out by the Haqqani network, a lethal arm of the Taliban.

United States Special Forces units advise Afghan forces in their operations in Nangarhar, and they are often engaged in combat there, too. On Jan. 1, one soldier, Sgt. First Class Mihail Golin, 34, was killed in the Achin district when a patrol was targeted, making him the first military casualty of 2018, the Pentagon announced Wednesday.