President Biden declared Tuesday that “the war in Afghanistan is now over” in an address that was less a celebration of a mission accomplished than a somber eulogy for a 20-year endeavor that cost the country much but whose burden was borne by few.

From the White House, Biden gave a grim speech to mark the conclusion of a grim conflict, alternately offering explanation, defiance and justification as he reiterated that “it was time to end this war” and promising anyone who attacks Americans that “we will hunt you down.”

But Biden also recognized the criticism that accompanied the war’s chaotic ending, taking pains to reject the contention that in orchestrating a frenzied exit, he had abandoned Americans and vulnerable Afghans to the mercies of the Taliban.

Speaking in the midafternoon, rather than a prime-time slot that might have been expected to mark the end of a two-decade war, Biden argued that President Donald Trump, in signing the initial withdrawal deal with the Taliban, had left him only two options: honoring that deal or reneging and sending in thousands more troops.

“That was the choice, the real choice — between leaving and escalating,” Biden said. “I was not going to extend this forever war, and I was not extending a forever exit.”

Biden’s speech followed nearly a month of chaotic images from inside Afghanistan after the Taliban seized control far more ­swiftly than the president and his advisers anticipated. It also came less than a week after a suicide bombing outside the Kabul airport left 13 U.S. service members and more than 100 Afghans dead.

Video filmed on Aug. 30 showed the last U.S. troops to leave Kabul, ending a 20-year war. (Reuters)

He lauded “the extraordinary success of this mission,” framing the evacuation effort as a historic accomplishment, but there was little in his address that was ebullient or exultant, either in substance or delivery.

Biden has faced rebukes, even from allies, over the as many as 200 Americans still stranded in Afghanistan, as well as the turbulent execution of his exit strategy, and he devoted a good part of his remarks to pushing back on the narrative that he was leaving Americans behind in a treacherous battlefield.

“For those remaining Americans, there is no deadline,” Biden said. “We remain committed to get them out if they want to come out.”

He spoke of the thousands of people his administration helped to evacuate in the final days: the more than 5,500 Americans, the roughly 2,500 locally employed U.S. Embassy staffers and their families, the thousands of Afghan translators and interpreters who worked alongside Americans during the war.

“Most of those who remain are dual citizens, longtime residents who had earlier decided to stay because of their family roots in Afghanistan,” Biden said. The White House said 98 percent of Americans wishing to leave had been evacuated.

Republicans are divided over the wisdom of leaving Afghanistan, with some arguing for a long-term commitment and others saying the time has come to cut America’s losses. But they have coalesced around a message that Biden is shamefully abandoning Americans, and House Minority Leader Kevin McCarthy (R-Calif.) demanded before the address, “What is the plan to get Americans out?”

McCarthy added, “Never in my lifetime would I ever believe America would have an administration knowingly make a decision to leave Americans behind, whereas just two weeks ago, the president promised this nation that he would not leave until every single American was out.”

Biden spoke emphatically at moments, almost shouting the first part of his speech, and in a whispery hush at others, lowering his voice to make a point. At times, he drummed his index finger on the lectern, as if to physically hammer home the arguments he’s been making since announcing the withdrawal this year.

While declaring, “I take responsibility for the decision,” the president also seemed eager to preempt and rebut his critics, at points doing so explicitly.

“Some say we should have started mass evacuations sooner, and, ‘Couldn’t this have been done in a more orderly manner.’ I respectfully disagree,” Biden said. “The bottom line is, there is no evacuation from the end of a war that you can run without the kinds of complexities, challenges and threats we faced. None.”

He continued: “To those asking for a third decade of war in Afghanistan, I ask: What is the vital national interest? . . . We succeeded in what we set out to do in Afghanistan over a decade ago. Then we stayed another decade.”

Biden returned again to the core arguments he has deployed throughout the withdrawal debate — that the war had long since run its course; that American national security objectives were accomplished years ago, including the 2011 killing of Osama bin Laden; that the Afghans need to govern and defend themselves; and that any extension of the war would only serve to put more Americans in harm’s way.

Biden in effect sought to turn the criticism on its head, saying his hasty withdrawal reflected a deep concern for the armed forces. He stressed the cost of the war for military families and said the departure would allow the United States to focus on its true adversaries, China and Russia.

“When I hear that we could’ve, should’ve continued the so-called low-grade effort in Afghanistan, at low risk to our service members, at low cost, I don’t think enough people understand how much we have asked of the 1 percent of this country who put that uniform on, who are willing to put their lives on the line in defense of our nation,” Biden said.

The president spoke of the physical toll the war has taken, from lost limbs to traumatic brain injuries, and the emotional one, from divorces to missed birthdays. He cited the 18 veterans a day, on average, who die of suicide.

“There’s nothing low-grade or low-risk or low-cost about any war,” he said. “It’s time to end the war in Afghanistan.”

Biden also made sure to cite Trump’s deal with the Taliban to leave the country by May 1, albeit without mentioning the former president by name, as a way to highlight that many Republicans, including some who have been critical of his execution, have supported the decision to end the war.

More broadly, Biden reiterated his argument that America’s priorities now lie elsewhere and that 20 years on, the terrorist threat has “metastasized” in ways that make an ongoing military presence in Afghanistan unnecessary and counterproductive. The United States invaded Afghanistan in response to the Sept. 11, 2001, terrorist attacks, to strike back at the al-Qaeda terrorists responsible for the assault.

But things have become unrecognizable in two decades, Biden said.

“The fundamental obligation of a president, in my opinion, is to defend and protect America — not against threats of 2001, but against the threats of 2021 and tomorrow,” Biden said.

That argument may ring differently, however, since the Islamic State-Khorasan terrorist attack last week that killed 13 American troops.

“To ISIS-K: We are not done with you yet,” Biden warned. “The United States will never rest. We will not forgive. We will not forget. We will hunt you down to the ends of the Earth, and you will pay the ultimate price.”

Still, it is unclear whether, in the vacuum left by the U.S. withdrawal, Afghanistan’s jagged mountains will again become a safe haven for terrorist organizations like al-Qaeda and the Islamic State. The United States will also need to find ways to continue its intelligence-gathering capabilities, now with far fewer on-the-ground operatives.

Questions also remain about what an Afghanistan under Taliban rule will look like. Many foreign policy experts predict that the so-called softer “Taliban 2.0” — which has promised, for instance, to respect the rights of women within the confines of its interpretation of Islamic law — will be not be dissimilar from the organization that came before it.

Biden said the United States will continue the fight against terrorism in Afghanistan and other countries. “We just don’t need to fight a ground war to do it,” he said.

The U.S. retaliatory strike against the Islamic State group that claimed responsibility for the suicide bombing at the Kabul airport’s Abbey Gate is an example, Biden said.

Not everyone was swayed. In a statement after the speech, Sen. Ben Sasse (R-Neb.), a member of the Senate Intelligence Committee, slammed what he called “Biden’s unseemly victory lap” as “detached from reality.”

“His callous indifference to the Americans he abandoned behind enemy lines is shameful,” Sasse said. “He promised the Taliban that our troops would leave by his arbitrary August 31st deadline, and he promised the American people that our troops would stay until every American was out. He kept his promise to the Taliban and lied to the American people.”

Biden, meanwhile, said the United States should learn from its mistakes over the two decades of war in Afghanistan — and shortly after his speech, White House press secretary Jen Psaki was asked whether the president had identified any of his own mistakes that could provide lessons.

“I think the president has been pretty clear that we all had an expectation that the Afghan national security forces would fight harder, at the end, would fight against the Taliban,” Psaki said. “We all had an expectation that President [Ashraf] Ghani would not flee the country. Those were not expectations that were clearly met.”

In addition to being the president who ended the war, Biden’s legacy will also include being the U.S. leader who presided over the return of Taliban rule to Afghanistan after two decades, more than 2,400 U.S. combat deaths and trillions in spending. He will also now be the president who decides whether the United States will establish a formal diplomatic relationship with its recent enemy.

“Well, just like in any circumstance, it would depend on the conditions,” Psaki said. “But there’s no rush to recognition coming from any aspect of this government or from the international community.”

Cleve R. Wootson Jr. contributed to this report.