Even before the Taliban’s stunning takeover this week, American military and intelligence officials were racing to devise plans for containing extremist threats emanating from Afghanistan, a task they knew would be more difficult following completion of President Biden’s order to withdraw U.S. forces.

Now, as the militants commandeer Afghanistan’s security and intelligence institutions, the Biden administration faces a far steeper challenge in fulfilling the president’s pledge to prevent al-Qaeda, the Islamic State and other terrorist groups that have operated there from regaining strength and threatening the United States.

Current and former officials said that the process for identifying and responding to terrorist plots has been upended as the Pentagon and the CIA — instead of planning for operations alongside an allied government and friendly spy agency in Kabul — are forced to contemplate an environment abruptly off-limits and under the control of a hostile regime.

After working for the Americans in Kabul, Mohammad came to the U.S. on a special immigrant visa in 2018. Now he worries about the family he left behind. (Whitney Leaming, Valerie Plesch/The Washington Post)

“The counterterrorism posture went from problematic with the U.S. withdrawal to extraordinarily bad with the Taliban in full control,” said Marc Polymeropoulos, a veteran intelligence officer who served as a CIA base chief in Afghanistan. “Suddenly one wonders if we will go entirely dark. It’s like a bad dream.”

At the same time, there are worrisome signs it may become more difficult for the United States to prevent a resurgence by al-Qaeda, which a recent United Nations report said maintained a presence in at least 15 Afghan provinces and showed “no indication of breaking ties” with the Taliban despite pledges to do so as part of a 2020 deal struck between the Afghan militants and Trump administration.

Foreign intelligence officials said they are detecting signs that the Taliban’s victory has energized global jihadists, a threat that may only grow as the Taliban releases al-Qaeda operatives who were imprisoned by the Afghan government.

An intelligence official from an Arab nation, who like others spoke on the condition of anonymity to describe evolving assessments, said officials had seen an uptick in jihadist communications about developments in Afghanistan. The Taliban takeover, this official said, “is encouraging many jihadists to think about traveling to Afghanistan now instead of Syria or Iraq.”

According to a European intelligence official, the Taliban’s victory has become a rallying cry for jihadist sympathizers there. “The U.S. appears in all of this now as a weak nation,” he said.

An al-Qaeda fighter who goes by the name Abu Khaled said the Taliban’s conquest was momentous for all extremists. “God willing, the success of the Taliban will be also a chance to unify mujahideen movements like al-Qaeda and Daesh,” he said, using another name for the Islamic State.

In April, CIA Director William J. Burns told lawmakers it would be harder to track al-Qaeda and other extremist groups without the bases and medical and air support the 20-year military effort in Afghanistan had provided, but said the agency would “retain a suite of capabilities.”

Now, most if not all of the capabilities the United States had envisioned within Afghanistan are no longer possible. While officials have not yet said what kind of engagement they might seek, if any, with the new Taliban government, the sprawling U.S. Embassy in Kabul is likely to remain shuttered in the near term. For now, one official said Monday, the U.S. military remains focused on evacuating Americans and their allies who are stranded in the Afghan capital.

In coming weeks, the Pentagon, CIA and other agencies will pivot to reshaping counterterrorism plans drawn up after Biden’s April announcement that he would withdraw U.S. forces.

Because Afghanistan’s neighbors won’t allow Americans to launch such flights from their territory, Washington’s plan has been to fly drones from existing facilities farther away in Gulf nations, gathering imagery about militant activity and striking targets as needed. The remote basing would have made the endeavor far more expensive, and less effective, than what U.S. military and intelligence officials conducted for years out of a large network of bases and airfields across Afghanistan, but there was little choice otherwise.

The Biden administration also planned to continue intelligence operations out of the U.S. Embassy in Kabul, working with the National Directorate of Security (NDS), the Afghan spy agency built by the CIA, to manage agents across the country. Officials would also use satellites and local listening posts to scoop up communications intercepts, attempting to keep militant plotting in check.

Now, while the Biden administration might still attempt to fly drones from the Gulf, it will do so over hostile airspace. That will also make any manned flights risky, as U.S. pilots will face the prospect of attack and no combat rescue teams on the ground.

It is also unclear whether the Gulf states expected to permit Afghan flights — Qatar and the United Arab Emirates — might rethink their positions given the Taliban’s rise. The UAE was one of a handful of countries that recognized the Taliban’s previous government.

Speaking to reporters Monday, Pentagon spokesman Johny Kirby said the U.S. military had built up a network of counterterrorism facilities and partnerships across the region in the past 20 years.

“There’s not a scrap of the earth that we can’t hit if we need to,” he said. “Now is it more difficult to do counterterrorism strikes over the horizon? You bet. Do you have to travel more distances? Yes. Could it take more time? Yes. But it’s not like we haven’t done this before.”

Former officials said the situation in Afghanistan, rather than resembling conditions in places like Russia or China, sometime adversaries where spy agencies operate under challenging conditions, would be more similar to Iran — a “denied area” with no U.S. embassy or official CIA presence, and where espionage options are severely limited and highly risky.

U.S. intelligence officials had previously said it would take up to two years for al-Qaeda to reconstitute in Afghanistan. Nathan Sales, who served as a senior counterterrorism official during the Trump administration, said that period could be as little as six months now.

“We are now back to 1998, where the Clinton administration was launching missiles at desert camps and hoping to hit something,” Sales said of earlier efforts to target al-Qaeda from afar. “That wasn’t enough to prevent 9/11, and returning to that is not a recipe for success.”

Officials will need to work out a host of other important questions, including whether U.S. spies attempt to rekindle resistance networks like the Northern Alliance, which the United States worked with before 2001, to collect intelligence or build a renewed resistance movement against the Taliban.

A related concern, one former senior Defense official said, is the likelihood that U.S. training in electronic espionage and other spycraft will be used by the Taliban, possibly to hunt down local adversaries or those who worked with foreign troops throughout the war.

William Wechsler, who served as a Pentagon official for special operations under President Barack Obama, said the Biden administration should reach out immediately to members of Afghanistan’s elite special forces, who fought alongside the United States and could serve as future allies or channels for intelligence. “We don’t want to lose them,” Wechsler said.

Greg Jaffe, Shane Harris and Karoun Demirjian contributed to this report.