A low-key ceremony in Kabul marked the formal end of NATO's war after 13 years of conflict that have left the country in the grip of worsening insurgent violence.
As of January 1, the US-led International Security Assistance Force (ISAF) combat mission, will be replaced by a NATO "training and support" mission.
Obama called the ceremony "a milestone for our country."
"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," he said in a statement.
Also Read
Obama thanked the troops and intelligence workers who served in Afghanistan, crediting them with "devastating the core Al-Qaeda leadership, delivering justice to Osama bin Laden, disrupting terrorist plots and saving countless American lives."
"We are safer, and our nation is more secure, because of their service."
And he honored those who were wounded or killed in the long war, including more than 2,200 US soldiers who lost their lives to make "this progress possible."
Under a bilateral agreement with Kabul, about 12,500 foreign troops will remain in Afghanistan. They will not be involved in direct fighting, but will assist the Afghan army and police in their battle against the Taliban, who ruled from 1996 until 2001.
That's down from around 130,000 troops from 50 nations at the 2011 peak.
The remaining soldiers "will continue to face risks," Obama said, emphasizing "the enduring commitment of the United States to the Afghan people.