This story has been updated.
WASHINGTON (AP) -- President Barack Obama on Friday declared an end to the Iraq war, one of the longest and most divisive conflicts in U.S. history, announcing that all American troops would be withdrawn from the country by year's end.
Obama's statement put an end to months of wrangling over whether the U.S. would maintain a force in Iraq beyond 2011. He never mentioned the tense and ultimately fruitless negotiations with Iraq over whether to keep several thousand U.S. forces in Iraq as a training force and a hedge against meddling from Iran or other outside forces.
Instead, Obama spoke of a promise kept, a new day for a self-reliant Iraq and a focus on building up the economy at home.
"I can report that, as promised, the rest of our troops in Iraq will come home by the end of the year," Obama said. "After nearly nine years, America's war in Iraq will be over."
Obama spoke after a private video conference with Iraqi Prime Minister Nouri al-Maliki, and he offered assurances that the two leaders agreed on the decision.
The U.S. military presence in Iraq stands at just under 40,000. All U.S. troops are to exit the country in accordance with a deal struck between the countries in 2008 when George W. Bush was president.
Obama, an opponent of the war from the start, took office and accelerated the end of the conflict. In August 2010, he declared the U.S. combat mission over.
"Over the next two months our troops in Iraq, tens of thousands of them, will pack up their gear and board convoys for the journey home," Obama said. "The last American soldier will cross the border out of Iraq with their heads held high, proud of their success and knowing that the American people stand united in our support for our troops."
More than 4,400 American military members have been killed since the U.S. and its allies invaded Iraq in March 2003.
Two U.S. officials had told The Associated Press last week that the United States would not keep troops in Iraq past the year-end withdrawal deadline, except for some soldiers attached to the U.S. Embassy.
In recent months, Washington had been discussing with Iraqi leaders the possibility of several thousand American troops remaining to continue training Iraqi security forces.
Throughout the discussions, Iraqi leaders refused to give U.S. troops immunity from prosecution in Iraqi courts, and the Americans refused to stay without that guarantee.
Moreover, Iraq's leadership has been split on whether it wanted American forces to stay.
When the 2008 agreement requiring all U.S. forces to leave Iraq was passed, many U.S. officials assumed it would inevitably be renegotiated so that Americans could stay longer.
The U.S. 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 American military help. But as the year wore on and the number of American troops that Washington was suggesting could stay behind dropped, it became increasingly clear that a U.S. troop presence was not a sure thing.
The issue of legal protection for the Americans was the deal-breaker.
Pulling troops out by the end of this year allows both al-Maliki and Obama to claim victory.
Obama kept a campaign promise to end the war, and al-Maliki will have ended the American presence and restored Iraqi sovereignty.
The president used the war statement to once again turn attention back to the economy, the domestic concern that is expected to determine whether he wins re-election next year.
"After a decade of war the nation that we need to build and the nation that we will build is our own, an America that sees its economic strength restored just as we've restored our leadership around the globe."
This is a breaking news story. Stay tuned for updates.