Defense Secretary Leon Panetta arrived Thursday in Baghdad for a special ceremony to formally shut down the war.
The flag of U.S. Forces-Iraq was officially retired. Troops lowered the flag and wrapped it in camouflage, formally "casing" it, according to Army tradition.
Panetta told troops that they leave Iraq with lasting pride, adding that their sacrifice "helped the Iraqi people to cast tyranny aside."
The U.S. invaded Iraq in March 2003. The war left 4,500 Americans dead, 32,000 wounded and cost more than $800 billion.
At the height of the surge, there were close to 170,000 U.S. troops in Iraq. That number is down to about 4,000, and those troops should be out of the country by the end of the year.
U.S. officials were negotiating to extend the stay of U.S. forces, but they could not reach an acceptable agreement with the Iraqi government.
Ambassador Jim Jeffrey made it clear the U.S. will continue to work closely with Iraq.
"We also look forward to an Iraq that is sovereign, secure and self-reliant, an Iraq with whom the U.S. will continue to work in every way possible," said Jeffrey.
President Barack Obama met in Washington with Iraqi Prime Minister Nouri al-Maliki earlier this week, vowing to remain committed to Iraq as the two countries struggle to define their new relationship.
The Associated Press contributed to this report.