The ceremony marking the closure of the US military's headquarters in Iraq comes after US President Barack Obama hailed the "extraordinary achievement" of the war in a speech to welcome home some of the troops. 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." In Afghanistan, US Defence Secretary Leon Panetta said he would be heading to Iraq to attend the ceremony to "encase the flag and mark the end of the combat effort that we've made as a country." "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 told US soldiers. "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," said Panetta. But "the fact is that we've given them the opportunity to be able to succeed."