Celebratory gunfire echoed across Kabul as Taliban fighters took control of the airport before dawn on Tuesday following the withdrawal of the last US troops, ending 20 years of war that left the Islamic militia stronger than it was in 2001.

Shaky video footage distributed by the Taliban showed fighters entering the airport after the last US troops took off a minute before midnight, marking the end of a hasty and humiliating exit for Washington and its Nato allies.

“The last US soldier has left Kabul airport and our country gained complete independence,” Taliban spokesperson Qari Yusuf said, according to Al Jazeera TV.

The US Army shared an image taken with night-vision optics of the last US soldier to step aboard the final evacuation flight out of Kabul — Major General Chris Donahue, commander of the 82nd Airborne Division.

America’s longest war took the lives of nearly 2,500 US troops and an estimated 240,000 Afghans, and cost some $2 trillion.

Though it succeeded in driving the Taliban from power and stopped Afghanistan being used as a base by al Qaeda to attack the US, it ended with the hardline Islamic militants controlling more of the country than they ever did during their previous rule from 1996 to 2001.

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.