Those years were marked by the brutal enforcement of the Taliban's strict interpretation of Islamic law, and the world is now watching to see whether it forms a more moderate and inclusive government in the months ahead.
Thousands of Afghans have already fled fearing Taliban reprisals. A massive but chaotic airlift by the US and its allies over the past two weeks succeeded in evacuating more than 123,000 people from Kabul, but tens of thousands who helped Western countries during the war were left behind.
A contingent of Americans, estimated by US Secretary of State Antony Blinken as under 200 and possibly closer to 100, wanted to leave but were unable to get on the last flights.
General Frank McKenzie, commander of the US Central Command, told a Pentagon briefing that the chief US diplomat in Afghanistan, Ross Wilson, was on the last C-17 flight out.
“There's a lot of heartbreak associated with this departure. We did not get everybody out that we wanted to get out. But I think if we'd stayed another 10 days, we wouldn't have got everybody out,” McKenzie told reporters.
As the US troops departed, they destroyed more than 70 aircraft, dozens of armoured vehicles and disabled air defences that had thwarted an attempted Islamic State rocket attack on the eve of the US departure.
President Joe Biden, in a statement, defended his decision to stick to a Tuesday deadline for withdrawing US forces. He said the world would hold the Taliban to their commitment to allow safe passage for those who want to leave Afghanistan.
“Now, our 20-year military presence in Afghanistan has ended,” said Biden, who thanked the US military for carrying out the dangerous evacuation. He plans to address the American people on Tuesday afternoon.
Biden has said the US long ago achieved the objectives it set in ousting the Taliban in 2001 for harbouring al Qaeda militants who masterminded the Sept. 11 attacks on the US.
The president has drawn heavy criticism from Republicans and some of his fellow Democrats for his handling of Afghanistan since the Taliban took over Kabul earlier this month after a lightning advance and the collapse of the US-backed government.
Senator Ben Sasse, a Republican member of the Senate Intelligence Committee, called the US withdrawal a “national disgrace” that was “the direct result of President Biden’s cowardice and incompetence.”