US President Barack Obama has marked the end of the war in Iraq with a speech in which he welcomed home thousands of US troops.

The war, which lasted nearly nine years, killed at least 60,000 Iraqis and 4,500 US troops.

According to President Obama, the financial cost of the war is more than $1 trillion.

He said that the Americans were leaving behind a sovereign, stable, and self-reliant Iraq, with a representative government that was elected by its people.

Addressing soldiers at Fort Bragg, North Carolina, home of the 82nd Airborne Division, Mr Obama stopped short of declaring victory in Iraq but called the winding down of the conflict "an extraordinary achievement".

"It is harder to end a war than to begin one," he told about 3,000 soldiers gathered in an airplane hangar as they punctuated his speech with cheers and hollers.

Despite lingering questions about whether the US should have invaded the Middle Eastern country, the last American troops "will cross the border out of Iraq with their heads held high," Mr Obama said.

"Of course, Iraq is not a perfect place. But we are leaving behind a sovereign, stable and self-reliant Iraq, with a representative government that was elected by its people," he said. "We are ending a war not with a final battle, but with a final march toward home."

As of this week, there were about 5,500 US troops left in Iraq, down from more than 170,000 at the height of the war that Mr Obama's predecessor George W Bush started in the wake of the 11 September 2001 attacks.

Michelle Obama, speaking just before her husband, injected a hint of campaign rhetoric by crediting the president for winding down the war. "He's kept his promise to responsibly bring you home from Iraq," she told the Fort Bragg soldiers.

Leaving Iraq fulfils a pledge that helped Mr Obama win the presidency in 2008 and allows the White House to focus more on Afghanistan as well as economic worries at home, where the high jobless rate will be a major concern for voters next year.

But critics have accused President Obama of ending the war hastily to suit his re-election campaign, warning the US departure could embolden insurgent fighters as well as Iraq's neighbour, Iran.