President Biden on Monday acknowledged the “gut-wrenching” spectacle of chaos and desperation in Afghanistan as Americans leave after 20 years, but said he is resolute in his decision to close down a war effort that had long ago lost its way.

Biden largely blamed others for the departure debacle and said the stunning collapse of U.S.-backed Afghan leadership amid a Taliban blitz confirmed that he was right to order the United States out of the country, the focus of anti-terror and democratizing efforts since shortly after the Sept. 11, 2001, attacks on the United States. He admitted that his administration was surprised by swift-moving events that have put the militia group in control, led to the shuttering of the U.S. Embassy and drove thousands to seek refuge by fleeing to the Kabul airport. Biden said he has no regrets.

“I stand squarely behind my decision,” he said during a hastily arranged speech from the White House, as more U.S. troops were ordered to Kabul to try to keep order amid scenes of despair and mayhem in the capital.

Facing the first foreign policy crisis of his presidency, Biden made no firm promises to Afghan interpreters and others whose work for the American enterprise has made them vulnerable, nor to Afghan women and girls whose rights and futures are in doubt under Islamic fundamentalist rule.

“Our mission in Afghanistan was never supposed to have been nation building,” Biden said. “ . . . Our only vital national interest in Afghanistan remains today what it has always been: preventing a terrorist attack on the American homeland.”

Brushing aside broad criticism that the United States was abandoning allies and breaking commitments, Biden said the situation was ultimately not within U.S. power or responsibility to fix.

“I’m left again to ask of those who argue that we should stay: How many more generations of America’s daughters and sons would you have me send to fight Afghans — Afghanistan’s civil war — when Afghan troops will not? How many more lives — American lives — is it worth? How many endless rows of headstones at Arlington National Cemetery?” Biden asked.

“I’m clear on my answer: I will not repeat the mistakes we’ve made in the past — the mistake of staying and fighting indefinitely in a conflict that is not in the national interest of the United States, of doubling down on a civil war in a foreign country, of attempting to remake a country through the endless military deployments of U.S. forces.”

In his first remarks since the collapse of the Afghan government and the military forces that the United States had trained for a generation, Biden repeatedly steered toward his opposition to staying in the country even with a minimal number of troops. That posture, which Biden has long held and campaigned on in 2020, is in line with American public opinion, which long ago tired of the international conflict.

But he did not explain why, months after he had vowed to withdraw by September, he and his administration were forced into a frantic evacuation that endangered both American citizens and Afghans who had aided the U.S. effort.

U.S. officials said they will accelerate the evacuation of thousands of Afghans eligible for special immigrant visas. About 2,000 Afghans have arrived in the United States over the past two weeks, a fraction of the estimated 88,000 who the State Department said could need to be evacuated. Other flights departed Afghanistan on Monday.

The end may have come faster than his administration had envisioned, Biden said, but that only served to underscore that the result was inevitable.

“The events we are seeing now are sadly proof that no amount of military force would ever deliver a stable, united, secure Afghanistan,” Biden said.

He said he wanted to acknowledge “how painful this is to so many of us.”

“The scenes we’re seeing in Afghanistan, they’re gut-wrenching, particularly for our veterans, our diplomats, humanitarian workers or anyone who has spent time on the ground working to support the Afghan people.”

The Taliban takeover could have come five years ago, or at whatever point in the future the United States pulled out. U.S. troops should not fight a war that Afghan forces are not willing to fight for themselves, Biden said.

“We gave them every chance to determine their own future. What we could not provide them was the will to fight for their future,” Biden said.

Biden said, as he did when he announced the pending withdrawal in April, that U.S. goals in Afghanistan were accomplished long ago with the routing of the al-Qaeda cell that planned the Sept. 11 terrorist attacks.

The twin goal of preventing Afghanistan from again becoming a haven for terrorists can be accomplished from afar, Biden said Monday.

“I am President of the United States of America, and the buck stops with me,” he said.

“I am deeply saddened by the facts we now face. But I do not regret my decision to end America’s warfighting in Afghanistan and maintain a laser focus on our counterterrorism missions there and in other parts of the world.”

But even as he asserted his ultimate responsibility for events in Afghanistan, the president spread blame for the response to others.

In addition to Afghan leaders and soldiers, Biden said his hands were tied by President Donald Trump, who had struck a deal with the Taliban last year for a U.S. withdrawal. Reneging on that deal, which was to take effect last May, would have made American soldiers vulnerable, Biden said.

“There was only the cold reality of either following through on the agreement to withdraw our forces or escalating the conflict and sending thousands more American troops back into combat in Afghanistan, lurching into the third decade of conflict,” Biden said. “After 20 years, I’ve learned the hard way that there was never a good time to withdraw U.S. forces.”

Trump, in a statement Monday, did not disagree with the withdrawal of U.S. forces but lanced Biden’s handling of it.

“It’s not that we left Afghanistan. It’s the grossly incompetent way we left!” Trump said.

While Biden asserted that his administration had “planned for every contingency,” he did not assign blame or take responsibility for U.S. officials’ failure to foresee how quickly the U.S.-trained soldiers would melt away or how swiftly the Taliban would overrun the elected government.

The insurgents, who led Afghanistan from 1996 to 2001, mounted a staggering campaign this month that saw them seize most of the country in a matter of weeks, facing little resistance from Afghan security forces, many of whom surrendered or fled their posts. Reporters in Kabul aired video of crews of armed militia members controlling intersections in the city, including one in front of the abandoned U.S. Embassy.

Monday’s images of disorder and confusion, including a video showing desperate Afghans clinging to the sides of a U.S. military aircraft as it moved down the runway at the Kabul airport, were some of the most harrowing to emerge in the days since the Taliban began seizing major cities.

U.S. military officials privately harbored fundamental doubts for the duration of the war that the Afghan security forces could ever become competent or shed their dependency on U.S. money and firepower, according to documents obtained for the forthcoming book “The Afghanistan Papers: A Secret History of the War,” written by Washington Post reporter Craig Whitlock.

“Thinking we could build the military that fast and that well was insane,” an unnamed former U.S. official told government interviewers in 2016.

But the U.S. involvement nonetheless carried through four presidencies, from George W. Bush to Barack Obama and finally to Trump and Biden.

The Afghanistan withdrawal tests Biden’s leadership and presents him with criticism from across the political spectrum, from conservative and liberal advocates for former translators, as well as humanitarian and human rights groups worried about the treatment to come for women and girls.

Biden said the United States would “continue to speak out” for the rights of Afghan women “just as we speak out all over the world,” but did not suggest that the United States bears any special responsibility to those women, who credit the American presence for their ability to secure an education and experience personal freedoms.

Biden interrupted a summer vacation at the Camp David presidential retreat to fly to the White House for the speech. When the speech ended, he returned to Camp David.