US forces held a formal ceremony to lower the flag in Iraq on Thursday, ahead of their withdrawal from the country nearly nine years after the controversial invasion to topple Saddam Hussein.
The ceremony marking the closure of the US military's headquarters near Baghdad comes after US President Barack Obama hailed the "extraordinary achievement" of the war in a speech to welcome home some of the troops.
It was attended by US Defence Secretary Leon Panetta, General Lloyd Austin, the commander of American forces in Iraq, and the US ambassador to Baghdad James Jeffrey.
Iraq was represented by military chief of staff Lieutenant General Babaker Zebari, and defence ministry spokesman Major General Mohammed al-Askari.
There are a little more than 4,000 US soldiers in Iraq, but they will depart in the coming days, at which point almost no more American troops will remain in a country where there were once nearly 170,000 personnel on more than 500 bases.
The withdrawal will end a war that left tens of thousands of Iraqis and nearly 4,500 American soldiers dead, many more wounded, and 1.75 million Iraqis displaced, after the 2003 US-led invasion unleashed brutal sectarian fighting.
In an aircraft hangar at Fort Bragg in North Carolina, Obama was cheered by soldiers as he honoured nearly nine years of "bleeding and building."
"Tomorrow (Thursday), the colors of United States Forces - Iraq, the colours you fought under, will be formally cased in a ceremony in Baghdad," he said.
"One of the most extraordinary chapters in the history of the American military will come to an end. Iraq's future will be in the hands of its people. America's war in Iraq will be over."
On Wednesday, Panetta said in Afghanistan he was heading to Iraq for the ceremony to "encase the flag and mark the end of the combat effort that we've made as a country."
Signup to our newsletter and follow us on Facebook and Twitter!
"Our mission there was to establish an Iraq that would be sovereign and independent, that would be able to govern and secure itself. And I think we've done a great job there in trying to achieve that mission," he said.
"It doesn't mean they're not gonna face challenges in the future. They're gonna face terrorism, they're gonna face challenges from those that will want to divide their country, they'll face challenges from just the test of.. a new democracy and trying to make it work.
But "the fact is that we've given them the opportunity to be able to succeed," said Panetta.
The military ceremony comes a day after hundreds of people in Fallujah marked the impending departure of American forces by burning US flags and shouting slogans in support of the "resistance."
Fallujah, a city of about half a million people west of Baghdad, remains deeply scarred by two American military offensives in 2004, the latter of which is considered one of the fiercest for the United States since Vietnam.
Obama's predecessor George W. Bush ordered the invasion of Iraq in 2003, arguing its then leader Saddam Hussein was endangering the world with weapons of mass destruction programmes.
Saddam was toppled and later executed, but such arms were never found.
Obama made his political career by opposing the war. In late 2002, he said he was against "dumb wars" such as Iraq, and rode anti-war fervor to the White House by promising to bring troops home.
The war was launched in March 2003 with a massive "shock and awe" campaign, followed by eight-plus years in which a US-led coalition sought not only had to rebuild the Iraqi military from the ground up, but also to establish a new political system.
Iraq now has a parliament and regular elections, and is ruled by a Shiite-led government that replaced Saddam's Sunni-dominated regime.
The pullout, enshrined in a 2008 bilateral pact, is the latest stage in the changing US role in Iraq, from 2003-2004 when American officials ran the country to 2009 when the United Nations mandate ended, and last summer when Washington officially ended combat operations.