Stretching more than eight years, the war cost the United States heavily: More than 4,400 members of the military have been killed, and more than 32,000 have been wounded.
The final exit date was sealed after months of intensive talks between Washington and Baghdad failed to reach agreement on conditions for leaving several thousand U.S. troops in Iraq as a training force. The U.S. also had been interested in keeping a small force to help the Iraqis deal with possible Iranian meddling.
The task now is to speed the pullout of the remaining U.S. forces, nearly 40,000 in number.
Staying behind in Iraq, where bombings and other violence still occur, will be some 150-200 U.S. military troops as part of embassy security, the defense attache's office and the office of security cooperation. That's common practice but still a danger to American forces.
Obama, an opponent of the war since before he took office, nevertheless praised the efforts of U.S. troops in Iraq. He said American soldiers would leave "with their heads held high, proud of their success."
For Obama, Friday's announcement capped a remarkable two days of national security successes, though there's no indication how much they will matter to re-election voters more concerned with economic woes at home.
On Thursday, the president heralded the death of Libyan dictator Moammar Gadhafi and a day later the end to one of the most divisive conflicts in U.S. history.
The wars in Iraq and Afghanistan have cost the U.S. more than $1.3 trillion.
Obama did not declare victory.
He did speak, though, about the string of wins on his watch - none bigger than the killing of Osama bin Laden, the al-Qaida leader behind the Sept. 11, 2011 terrorist attacks. The Afghanistan war still rages, but there, too, Obama has moved to end the combat mission by the end of 2014.
This was, in essence, the third time Obama had pronounced an end to the war, allowing him to remind the nation he had opposed it all along - a stance that helped his White House bid in 2008.
Shortly after taking office, Obama declared in February 2009 that the combat mission in Iraq would end by Aug. 31, 2010. And when that milestone arrived, he said it was "time to turn the page" on Iraq and put the focus back on building up the United States. On Friday, he said: "After nearly nine years, America's war in Iraq will be over."
The U.S.-led invasion of Iraq was launched in March of 2003 after reports, later discredited, that the country was developing weapons of mass destruction. By early April, American Marines were helping Iraqis pull down a statue of Saddam Hussein in Baghdad. Saddam was captured in December of that year and executed in 2006, but the war dragged on.
The ending was set in motion before Obama took office. In 2008, President George W. Bush approved a deal calling for all U.S. forces to withdraw by Dec. 31, 2011.
At issue was whether that deal would be renegotiated to keep thousands of U.S. forces in Iraq. The Obama administration and Iraqi government spent months debating whether the United States would keep troops to maintain a training force, to provide added stability in a country where spectacular attacks still occur, and to serve as a hedge against Iran.
Throughout the talks, Iraqi leaders refused to give U.S. troops immunity from prosecution in Iraqi courts, and the Americans refused to stay without that guarantee.
Obama never mentioned that issue on Friday.
He said that after speaking with Iraqi Prime Minister Nouri al-Maliki, both were in agreement on how to move forward. Obama said the two nations will now deal with each in the normal fashion of sovereign countries and will keep open the idea of how the United States might help train and equip Iraqi forces.
"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 the American people stand united in our support for our troops."
The Associated Press first reported 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.
"Both countries achieved their goals," said Iraqi government spokesman, Ali al-Moussawi. "Iraq wanted full sovereignty while the United States wanted its soldiers back home, and both goals are achieved."
In addition to remaining military forces, Denis McDonough, White House deputy national security adviser, said the U.S. will have 4,000 to 5,000 contractors to provide security for American diplomats.
Obama's announcement was applauded by congressional Democrats, including Senate Majority Leader Harry Reid, who called it "the right decision at the right time."
Republicans were more skeptical. Many praised the gains made in Iraq and gave Obama at least partial credit but expressed concern that getting troops out would bring that progress into question.
Sen. Lindsey Graham, R-S.C., said he feared that "all we have worked for, fought for and sacrificed for is very much in jeopardy by today's announcement. I hope I am wrong and the president is right, but I fear this decision has set in motion events that will come back to haunt our country."
GOP presidential hopeful Mitt Romney accused Obama of an "astonishing failure" to secure an orderly transition in Iraq, and said, "The unavoidable question is whether this decision is the result of a naked political calculation or simply sheer ineptitude in negotiations with the Iraqi government."
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.
But administration officials said they feel confident that Iraqi security forces are well prepared to take the lead in their country.
McDonough said that one assessment after another of the preparedness of Iraqi forces concluded that "these guys are ready; these guys are capable; these guys are proven; importantly, they're proven because they've been tested in a lot of the kinds of threats that they're going to see going forward."
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.
"After a decade of war," he said, "the nation that we need to build and the nation that we will build is our own."
Associated Press writers Sameer N. Yacoub in Baghdad and Jim Kuhnhenn, Erica Werner and Lolita C. Baldor in Washington contributed to this story.