KABUL, Afghanistan — Even as the United States and the Taliban seem close to a deal on an American troop withdrawal, the Islamic State in Afghanistan is making clear that it stands to inherit the role of violent spoiler if any peace agreement is reached.
That message was punctuated on Saturday by a suicide bomber who killed 63 wedding celebrants in Kabul, mostly from the country’s Shiite minority, in an attack that the Islamic State attributed to one of its loyalists from Pakistan. It was among the most devastating attacks in Afghanistan claimed by the Islamic State in the five years since it first established a beachhead in the eastern part of the country.
The bombing was a painful reminder of the immediate threat posed by the militants: that they can slip through tight security in the capital and cause the kind of carnage that devastates a vulnerable community, while cranking up pressure on a government already on the edge.
But the Islamic State also poses a longer-term danger that the United States military and Afghan officials worry about: It has positioned itself to gain in the event of a peace deal with the Taliban. The Islamic State is set to grow if an extreme layer of insurgents breaks away from the Taliban to keep fighting, and it is likely to thrive if a hastily managed American military withdrawal leaves chaos behind.
“This is a replacement for the Taliban,” said Abdul Rahim Muslimdost, an Islamist cleric who has been jailed in Pakistan and in the American detention camp at Guantánamo Bay.
In an interview with The New York Times, Mr. Muslimdost explained how he helped create the Islamic State chapter in Afghanistan — mostly, he said, from former Pakistani and Afghan Taliban members. He said he had since dissociated himself from it, contending that it had been infiltrated by Pakistan’s military and intelligence services.
That view is shared by some Afghanistan security officials. They have consistently portrayed the Islamic State as the continuation of what they describe as Pakistan’s policy of “strategic depth,” in which it exerts influence in Afghanistan through militant proxies.
The Taliban, whose leadership operates out of Pakistan, had long been seen as that country’s main source of leverage in Afghanistan. But even though international pressure has led Pakistan to support the peace process with the Taliban, Afghan officials accuse the country’s military establishment of investing in the Islamic State’s local chapter to maintain its influence.
They say there is overlap between the support networks in Afghanistan and Pakistan that enable the Islamic State’s suicide bombings and the ones that helped the Taliban’s most lethal arm, the Haqqani network, carry out urban attacks for years.
“The responsibility of all these attacks — which are carried out with same tactics as the Taliban — goes to the Taliban,” said Massoud Andarabi, Afghanistan’s interior minister, even after the Islamic State claimed responsibility for the wedding bombing on Saturday.
“It is the Taliban who have created the networks that make possible such terrorist attacks in our cities, and now they claim responsibility when they want for an attack and not when they don’t,” Mr. Andarabi said.
American officials who have monitored the Islamic State’s development say there is no evidence that its chapter in Afghanistan gets support from Pakistan’s military establishment. Pakistani officials have also rejected the accusation, saying the military has backed away from its policy of nurturing militant groups. Islamic State affiliates have tried to carry out attacks in Pakistan, but with less frequency, as better security measures are in place there.
One American official acknowledged that there might be some modest overlap between the Islamic State and the Taliban, but described it as mostly being among low-ranking profiteers, not decision makers or trainers.
Sher Mohammad Karimi, a retired former chief of the Afghan Army, said it was worrying that Afghan officials and their American allies seemed to disagree about the extent of the Islamic State threat, and its source, at such a desperate time.
“It is a fact that Pakistan wants a weak government in Afghanistan so it can fulfill its strategic goals,” Mr. Karimi said. “But defending this country is our responsibility, and we should well prepare our forces.”
Different parts of the American government disagree over whether the local Islamic State chapter has either the capability or the ambition to strike the United States directly. But they agree that the group poses a threat that the United States needs to watch by maintaining counterterrorism units in Afghanistan, so that attacks like Al Qaeda’s strikes in 2001 cannot be repeated.
Two critics of the United States in the region, Russia and Iran, claim that the Islamic State here is being nurtured by the Americans in order to destabilize everything around it.
Since it was formed around 2014, the Islamic State’s Afghan chapter has been steeped in a long history of militancy in the region, a legacy of the C.I.A.’s use of Islamic jihadists, the mujahedeen, in its effort to defeat the Soviet Union in Afghanistan in the 1980s.
Mr. Muslimdost, the cleric who helped to found the Islamic State cell, was part of the mujahedeen effort. And his complex personal history epitomizes the legacy of perpetual insurgency and violence surrounding Afghanistan.
During the 1980s, he ran a library and published an Arabic magazine in the Pakistani city of Peshawar, a transit stop for the Arab fighters, including Osama bin Laden, who were coming to fight the Soviets in Afghanistan.
After the United States invaded Afghanistan in 2001 to destroy Mr. bin Laden’s new group, Al Qaeda, Mr. Muslimdost was among the hundreds of militants sent to Guantánamo, where he spent three years. He says that he had no formal role with the Taliban, and that Pakistan had wrongfully handed him over to the Americans.
After he was released from Guantánamo, Mr. Muslimdost wrote a book that was critical of Pakistan, in which he also described a dream about the formation of a global caliphate. The book landed him in a Pakistani prison.
When he came out, he allied with, and sought protection from, Pakistani militants who were fighting the state.
In the Islamic State’s 2014 declaration of a caliphate from Iraq, Mr. Muslimdost said he saw the opportunity for the fulfillment of a lifelong dream: that the Muslim world would unite under one government.
But right away, disagreements plagued the group he helped to form. He wanted to fight in Pakistan, but other members had already established the base in eastern Afghanistan that they still hold.
Mr. Muslimdost said he realized that the group was out of his hands — infiltrated, he said, by elements of Pakistan’s intelligence agency, in order to push what was left of the militancy in Pakistan across the border. That infiltration intensified as the United States kept killing the group’s original leaders with drone strikes, he said.
Today, the Islamic State is active or present in nearly two dozen districts along the border with Pakistan, despite strong pressure from the American and Afghan militaries. The Afghan intelligence agency says it has also broken up Islamic State cells inside the capital, operating in universities and recruiting among the city’s educated elite.
Video
3:00How Many U.S. Wars Equal the One in Afghanistan?Afghanistan is America’s longest war — 18 years. That’s longer than World War I, World War II and the Korean War combined.
It is possible that concerns about the Islamic State could become a catalyst in the search for a deal with the Taliban. The two militant groups have fought many turf battles, and American officials say that in talks, the Taliban have said they do not want Afghanistan to become another Syria or Iraq.
But there is also widespread anxiety that the Islamic State has positioned itself for the fracturing of the Taliban in the event of a peace deal. Mr. Muslimdost agrees with that assessment, seeing Pakistan at work behind the scenes.
“Remember my words,” Mr. Muslimdost said. “If there is a settlement with the Taliban, and they become part of the government, Pakistan has the replacement for them ready already. They will continue this war in Afghanistan in the name of the Islamic State.”