US President Barack Obama has confirmed that all 39,000 US troops still stationed in Iraq will be withdrawn by the end of the year, bringing to an end an almost nine-year presence in the country since the 2003 invasion that toppled Saddam Hussein.

Obama's statement on Friday ended months of speculation over whether Washington would continue to base forces in the country beyond the end-of-year departure date set in place by Obama's predecessor, George W. Bush.

"After nearly nine years, America's war in Iraq will be over," Obama said in a statement at the White House, shortly after a private video conference with Nouri al-Maliki, the Iraqi prime minister.

Obama's statement represents the fulfillment of a central promise of his 2008 election campaign to end US involvement in Iraq, and comes with Washington also seeking to reduce its troop presence in Afghanistan.

Despite continuing controversy over the legality of the 2003 invasion and the years of violence that followed the end of Saddam's decades-long dictatorship, Obama said US troops would leave Iraq "with their heads held high, proud of their success."

When the 2008 agreement requiring all US forces to leave Iraq by 2012 was passed, many US officials assumed it would inevitably be renegotiated so that US forces could stay longer.

The US said repeatedly this year it would entertain an offer from the Iraqis to have a small force stay behind, and the Iraqis said they would like US military help.

But US-Iraqi talks broke down because the two sides were unable to agree on granting legal immunity for a small contingent of American troops who would have stayed in place to help train Iraqi forces.


 Rosiland Jordan on what Obama's announcement means for US-Iraqi relations

Throughout the discussions, Iraqi leaders had adamantly refused to give US troops immunity from prosecution in Iraqi courts, while US military officials had refused to stay without it.

Moreover, Iraq's leaders have been split over whether they wanted US forces to stay.

"It had become increasing apparent that it was going to be difficult for the two to reach a deal to allow some US forces to remain on Iraqi soil, come January 1, 2012, because of the details of the agreement they has signed," said Al Jazeera's Rosiland Jordan.

Obama said that he had invited Maliki to visit the White House in December, as the two sides revert to a normal sovereign relationship between two nations.

The US's military role in Iraq has been mostly reduced to advising the security forces in a country where levels of violence had declined sharply from a peak of sectarian strife in 2006-2007, but attacks remain a daily occurrence.

More than 4,400 American military personnel have been killed since the US-led invasion in March 2003.

Source: Al Jazeera and agencies