A bombing at a gate at Kabul’s international airport killed 11 U.S. Marines, one soldier, one Navy corpsman and dozens of Afghan civilians Thursday, throwing the final days of a U.S.-led evacuation effort into chaos and fulfilling a nightmare scenario President Biden’s top aides had desperately sought to avoid.

The explosion, which also wounded 18 Americans and scores of Afghans, came as the United States and other Western nations rushed to complete the evacuation of tens of thousands of citizens and Afghan allies ahead of an Aug. 31 deadline.

President Biden vowed to punish the those responsible but said the United States would continue running evacuation flights to bring Americans and Afghan allies home.

“We will hunt you down and make you pay,” Biden said before taking a moment of silence for those killed in the assault, the deadliest attack on U.S. forces in Afghanistan since 2011.

In keeping to his end-of-month withdrawal timeline, Biden acknowledged that some Americans and Afghan allies may be left in Afghanistan after troops leave but promised to help them get out by other “means.”

ISIS-Khorasan, the Islamic State’s Afghanistan and Pakistan arm, took responsibility for the attack in a statement, saying one of its adherents penetrated security barriers around the airport, dived into a large group of U.S. troops and Afghan civilians and detonated an explosives belt.

The target selected by ISIS was central to American military life in Kabul even before the evacuation effort. The Abbey Gate, on the southern side of the airport, has been used as a central entrance for U.S. forces and other visitors for years, as they traversed security and eventually made their way to military facilities on the northern side of the airport’s single runway.

A bombing that hit Kabul airport on Aug. 26 targeted crowds of people who were waiting near the Abbey Gate to enter the facility. (AP)

In recent days it has become a choke point of men, women and children amassed in the hope of escaping Taliban rule. Video of the aftermath showed twisted bodies, mostly of young men, piled on top of each other.

The toll of dead and wounded remained uncertain late Thursday. Earlier in the day, Taliban spokesman Zabihullah Mujahid said at least 13 people were killed in the explosions. Later, one person with knowledge of the matter, who spoke on the condition of anonymity because he was not authorized to speak to the media, said 40 were killed and 120 wounded. Other reports put the tally far higher. It was unclear whether those figures included the 13 U.S. service members.

Marine Gen. Kenneth F. McKenzie Jr., commander of U.S. Central Command, said a single suicide bomber carried out the terrorist attack at the airport gate.

“We thought this would happen sooner or later; it’s tragic that it happened today,” McKenzie said. “We’re prepared to continue the mission . . . even while receiving attacks like this.”

There was no indication that any State Department officials at the airport were killed.

About 1,000 Americans are believed to remain in Afghanistan, the State Department said Thursday, adding that it is in touch with most of them.

“The vast majority — over two-thirds — informed us that they were taking steps to leave,” a department spokesperson said. More than 100,000 people have been airlifted from Kabul in the U.S.-led evacuation effort to date, according to the department.

U.S. officials had intercepted communication from members of “ISIS-K” discussing a suicide vest attack ahead of the bombings, said a U.S. official who spoke on the condition of anonymity to discuss intelligence matters.

ISIS-K was formed six years ago by estranged members of the Pakistani branch of the Taliban and has carried out a number of attacks on Afghans and Taliban fighters in recent years.

The shared ISIS-K threat between the Taliban and the United States has turned the two enemies into temporary security partners after 20 years of combat.

At the airport, U.S. helicopters and drones fly above crowds and search for potential attackers. One of the last rings of security is in the hands of the Taliban, which has set up perimeters and checkpoints outside the airport.

U.S. forces have shared threat assessments and other information with Taliban leaders, and sought their assistance closing roads to forestall car bombings, McKenzie said. “We believe attacks have been thwarted by them,” he said.

In his remarks to reporters, Biden rejected critics who said the United States should not be cooperating with the Taliban on the defense of the airport perimeter.

“No one trusts them,” Biden said. “It’s a matter of mutual-self interest. . . . They’re not good guys, the Taliban. But they have keen interests,” he added.

Officials are investigating how the airport attack unfolded even as U.S. troops prioritized putting distance between civilians trying to enter through the gate and where they operate. While the attacker didn’t breach the gate, service members are in an inherently dangerous and close position because they have to search every potential evacuee, McKenzie said.

“This is close-up work. The breath of the person you are searching is upon you,” he said. “While we have overwatch in place, we still have to touch the clothes of the person coming in. I think you can all appreciate the courage and dedication that is necessary to do this job, and to do it time after time.”

Republicans in Congress cited the attack as another indication of what they say is a poorly executed withdrawal strategy even as some agreed with the overall decision to get out of the country. “An embarrassing spectacle, a diplomatic humiliation and a national security catastrophe,” said Sen. Ted Cruz (R-Tex.).

Defenders of the president said the attack vindicated Biden’s decision to rebuff European demands to extend the evacuation mission beyond the end of the month. After informing allies of his decision on Tuesday, Biden had said “the sooner we can finish, the better,” noting the threat posed by ISIS-K.

“Every day we’re on the ground is another day we know that ISIS-K is seeking to target the airport, attack both U.S. and allied forces and innocent civilians,” he said.

As the pace of the evacuation operation picked up in the last week after a slow start, so did efforts to help people gain entry to the airport, which for many Afghans fearful of the Taliban represented a sole remaining link to the outside world.

In hastily arranged message groups over the past few days, outsiders — including veterans trying to help former interpreters, aid officials attempting to assist local employees, and journalists partnering with local media — have shared information and potential leads for getting Afghan colleagues through the gates, often without success.

Even top officials from former president Ashraf Ghani’s government have struggled to leverage their relationships in Washington to get staff and relatives out. On Tuesday, the State Department sent what was described as a final notice for U.S. citizens wanting to be flown out. “American citizens who choose to remain in Afghanistan should be prepared to arrange their own departure without assistance from the U.S. government,” it said.

By Wednesday, advocates for Afghans said access at the airport has been dramatically restricted. They said that military personnel from the United States, Britain and other countries have gradually tightened requirements at the airport’s various gates, making it more difficult for anyone but American citizens or other foreign passport holders to get through. They believed the new restrictions may have reflected intelligence about increasing security threats of militant attacks like the one that occurred Thursday, or potentially the reality that the U.S. military would need to shift its focus to begin airlifting out its own personnel and equipment ahead of Aug. 31.

Many of the Afghans attempting to get into the airport, according to people in touch with them, have paperwork showing they are eligible for the special immigrant visa program, which provides expedited consideration to Afghans who worked as interpreters or in other jobs with the U.S. government, or for other categories of Afghans the Biden administration has promised to prioritize. Some have had seats assigned on flights chartered by private groups, ultimately missing those flights.

Analysts said the attack put Biden in a policy bind.

“Keep doing evacuations and risk more terror attacks at the airport that kill more people, or stop evacuations and keep people desperate to leave from leaving,” said Michael Kugelman, an Afghanistan expert at the Wilson Center. “Like so many other U.S. policy decisions about Afghanistan, there are no good options.”

Karoun Demirjian, Greg Jaffe and Claire Parker in Washington and Sudarsan Raghavan in Doha, Qatar, contributed to this report.