NATO formally ended its war in Afghanistan on Sunday, lowering its flag in a low-key ceremony after 13 years of fighting.
The event was arranged in secret for fear of a Taliban attack at a time when militants have demonstrated their ability to launch strikes on the capital Kabul seemingly at will. Live broadcasts were banned for security reasons.
The lack of fanfare indicated the uncertainty of the US-led North Atlantic Treaty Organisation over the country's future, as an insurgency continues to rage in the south and east of the country.
General John Campbell, the American commander who led NATO's International Security Assistance Force (ISAF), lowered the green and white mission flag, replacing it with one of a training and support mission known as Resolute Support.
"Together we have lifted the Afghan people out of the darkness of despair and given them hope for the future," he told assembled soldiers.
The mission ends officially at midnight on 31 December, after 3,485 military deaths. They include 2,200 Americans and 453 Britons.
About 12,500 foreign troops will stay on, to help train and advise Afghan forces.
Barack Obama paid tribute to the US personnel who lost their lives.
"Today's ceremony in Kabul marks a milestone for our country," he said in a statement.
"For more than 13 years, ever since nearly 3,000 innocent lives were taken from us on 9/11, our nation has been at war in Afghanistan. Now, thanks to the extraordinary sacrifices of our men and women in uniform, our combat mission in Afghanistan is ending, and the longest war in American history is coming to a responsible conclusion."
The departure ceremony, held in a sports hall at NATO headquarters, completed the handover to 350,000 Afghan troops.