KABUL — Despite its brutality and harsh Islamic codes, the Taliban was accepted by many Afghans who lived under its rule for a singular reason: The militants were thought to provide better security than previous governments, more so than any other force that had emerged in Afghanistan.

By Friday, that perception had been seriously damaged.

A day after an Islamic State-Khorasan suicide bomber killed 13 U.S. service members and at least 170 others at Kabul’s airport — one of the country’s deadliest terrorist episodes — there was little faith among some Afghans in the Taliban’s ability or willingness to prevent future attacks.

“When the Taliban took control of the country, they promised us security,” said Sadiq, a 33-year-old photographer who spoke on the condition that only his first name be used out of fear of reprisals. He was waiting with his relatives near the airport gate at the time of the explosion. He and his sister-in-law were unscathed, but the blast left his brother with severe shrapnel wounds to his legs.

“[The attack] shows that they failed in their promise,” he added. “I don’t believe they can prevent future bombings.”

The carnage underscored the vastly complicated and volatile landscape the Taliban finds itself in, raising questions about its capabilities to secure Afghanistan from terrorist and other attacks, especially in heavily populated urban areas. Unlike the first time the militants seized Afghanistan in 1996, when they quickly exerted control, they are facing challenges to their authority even before creating a government.

“The Taliban, up until recently, was the main party staging these attacks against civilians,” said Ashley Jackson, an expert on the Taliban at the Overseas Development Institute. “Now the roles have reversed rapidly. Now, they are in charge of security, in charge of protecting the population.”

“This is an enormous task,” she added. “They have had so little time to prepare for this transition.”

Today, the militants have to contend not only with anti-Taliban resistance forces but also extremist groups such as the Islamic State, which has grown powerful in recent months and wants the Taliban to fail in governing Afghanistan. Unlike in the 1990s, the Taliban is much more fragmented. Within the group’s own fold, there are radical commanders with competing visions of how to govern and bring security, who disagree with the moderate image that the upper echelon of leaders is trying to promote to the world.

Geographically, too, the militants face obstacles. Thanks to billions of dollars in American and Western aid, Kabul is now a booming, diverse metropolis of 6 million people, far larger and more developed than the capital the Taliban ruled decades ago. After their ouster in 2001, when U.S. forces entered Afghanistan following 9/11, the militants controlled swaths of rural hinterlands, but have little experience in securing and governing urban areas.

"[The] attack was a devastating loss of life, and it casts a long shadow of doubt on the Afghan Taliban's abilities to provide security and stability in Afghanistan," said Andrew Mines, a research fellow at George Washington University's program on extremism. "This is a precarious period for them as they try to project the appearance of security. Their claim to be the arbiter of security is very much being challenged."

The Taliban issued a statement condemning Thursday's bombing and vowed to launch a probe to "find those responsible and punish them." On Friday, spokesman Zabihullah Mujahid told The Washington Post that the area "was under the security of the Americans. So it was their responsibility."

But a senior Taliban commander acknowledged the attack exposed the group's vulnerability.

"This was a bad accident, but it informed us that we need to be more careful," said the senior Taliban commander, who is responsible for security in Kabul. The commander spoke on the condition of anonymity to discuss sensitive security matters.

"We need people to help us maintain security in Kabul, without people we can't do anything," he said. "We are asking the population to come forward with information about the case," he said, explaining that the group had maintained security in long-held districts through a tightknit network of informants.

But the commander admitted that using the same model to control a city as large as Kabul would not be adequate.

"The biggest difference is the population. When there are more people, there are more problems like crime and insecurity," he said. "It's easier for [terrorist] groups to hide among a big population."

The Taliban is also hampered by its own internal structure, analysts said. There are different groups of fighters on the streets with no clear chain of command and hardly any coordination, making it easier for guerrilla attacks to strike.

"What the Taliban will find is what the Afghan intelligence agency and the U.S. found: It is very hard to identify and target small cells that operate with good operation and security inside large urban areas," said Jonathan Schroden, who heads the Countering Threats and Challenges Program at the Center for Naval Analyses.

"It is a very brutal organization that will not hesitate to take brutal actions against these types of individuals," he added. "But still, the Taliban has to find them. That is much easier said than done."

The senior Taliban commander said the group is trying to monitor phone calls, Internet usage and other forms of communication to fight terrorism.

A former Afghan intelligence official said he has been surprised by how much more advanced the Taliban is now militarily, compared with 20 years ago, describing them as "more disciplined and better trained."

"I think they can handle [the Islamic State] if they want to," he said, speaking on the condition of anonymity out of fear of reprisals. But he added that he has seen the Taliban move its best fighters to Kabul, leaving cities such as Jalalabad, long home to Islamic State activity, more vulnerable.

Holding the Islamic State-Khorasan, as the Syria-based group's Afghanistan branch is called, accountable for Thursday's bombing is a key test of the Taliban's ability to govern and secure the country, analysts said.

But it remains to be seen whether the militants will act as they have in the past, hunting down ISIS-K and executing its commanders, or instead act as a government by making arrests and holding trials.

U.S. military commanders, as well as analysts, expect more attacks.

"The longer the transition takes for the Taliban, the more opportunities groups like the Islamic State will have for conducting attacks," Schroden said.

Outside a Kabul hospital treating blast victims on Friday, 46-year-old Zargona, a development worker whose husband was among the wounded, foresaw such a darker, more uncertain future.

"These explosions," she said, "this is just the beginning."