President Joe Biden on Tuesday defended what was widely perceived as a poorly handled pullout of U.S. troops from Afghanistan, while signaling that the end of the 20-year war will help the United States focus more on new challenges posed by China.

In his first public remarks since the last U.S. military plane left Afghanistan's capital Kabul on Monday, Biden hailed the operation to evacuate American citizens and locals who worked alongside the United States during the war as an "extraordinary success."

The final weeks of the pullout, however, were marred by chaotic images of Afghans desperately seeking to flee Afghanistan following the unexpectedly swift takeover of the country by the Taliban, as well as the deaths of 13 U.S. service members and dozens of Afghans in a terrorist attack near Kabul's international airport.

U.S. President Joe Biden arrives to deliver remarks on the end of the war in Afghanistan at the White House on Aug. 31, 2021 in Washington. (Getty/Kyodo)

Biden emphasized nearly all Americans who wanted to leave were able to exit Afghanistan and insisted, "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."

He had said earlier in August during a TV interview that the U.S. military would stay beyond his self-imposed troop withdrawal deadline of Tuesday until all American citizens could get out. But up to 200 Americans are believed to remain in Afghanistan with an intention of leaving, according to the U.S. government.

Biden vowed that his government will get these citizens out of the country if they desire to leave without setting a deadline, while disputing arguments that the United States should have continued a "low-grade effort" in Afghanistan.

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

The United States launched the war in response to the Sept. 11 terror attacks in 2001 by the al-Qaida organization, which was being harbored by the Taliban, a militant Islamist group.

The then Taliban regime was toppled by U.S.-led forces by the end of 2001 and al-Qaida leader Osama bin Laden, the mastermind behind the terror attacks, was killed in 2011.

U.S. forces remained in Afghanistan, however, to train and assist government security forces and to conduct counterterrorism operations.

The United States had been expecting the more than 300,000-strong Afghan security forces to be a capable adversary in fighting the Taliban. But as the Taliban seized city after city before taking control of Kabul on Aug. 15, Afghan forces collapsed in a matter of days and President Ashraf Ghani fled the country.

Biden said his decision on Afghanistan was not just about the war-torn country itself, but "about ending an era of major military operations to remake other countries."

"I simply do not believe that the safety and security of America is enhanced by continuing to deploy thousands of American troops and spending billions of dollars a year in Afghanistan," he said.

Biden also said the "fundamental obligation" of a president is to defend and protect the United States not against the threats of 2001, but against the threats of "2021 and tomorrow."

"The world is changing. We're engaged in a serious competition with China. We're dealing with the challenges on multiple fronts with Russia. We are confronted with cyberattacks and nuclear proliferation," he said.

"There's nothing China or Russia would rather have, would want more in this competition, than the United States to be bogged down another decade in Afghanistan," the president said.