WASHINGTON – President Barack Obama said Friday the United States would withdraw all its troops from Iraq by the end of the year, ending a long war that deeply divided the country over its origins and the American lives it consumed.

In a Friday morning video conference, Obama and Iraqi Prime Minister Nouri al-Maliki agreed to a complete U.S. military departure that will fulfill a promise important to Obama’s re-election effort. The decision drew sharp criticism from his Republican rivals, as well as expressions of relieved support from those who believe it is time for the United States to conclude a war Obama once called “dumb.”

For months, U.S. and Iraqi officials had been negotiating the terms of an accord that would have kept several thousand U.S. troops in Iraq for special operations and training beyond the year-end deadline set by the George W. Bush administration.

But Obama and Maliki, who have never developed much personal chemistry, failed to reach agreement on the legal status of U.S. troops who would stay in Iraq beyond Dec. 31. As a result, only a contingent of fewer than 200 Marines assigned to help protect the large U.S. Embassy compound in Baghdad will remain, along with a small number of other personnel to provide training related to new military sales and other tasks.

“The rest of our troops in Iraq will come home,” Obama said Friday at the White House, adding that they will “be home for the holidays.”

“After nearly nine years, America’s war in Iraq will be over,” he said.

The negotiations foundered over the U.S. demand that American troops receive legal immunity for their actions, a request Maliki was ultimately unable to sell to the anti-U.S. elements of his governing coalition after a war that many Iraqis believe has permanently altered their country for the worse.

The departure of U.S. forces could pose security problems for the Iraqi government, still beset by sectarian and ethnic divisions. There are 39,000 U.S. troops in Iraq today, about 100,000 fewer than when Obama took office. About 16,000 U.S. diplomats and civilian contractors will remain posted in Iraq.

If sectarian strife or other violence should break out in Iraq once U.S. forces have left, Obama could be blamed for abandoning Iraq before it was ready to protect itself. Such criticism came quickly Friday from Republicans vying for the presidency next year.

But the result also allows for a more definitive conclusion to the U.S. military intervention in Iraq, which has cost the United States nearly $1 trillion and more than 4,400 American lives. Obama, who separated himself from the crowded Democratic field in 2008 in part through his clear opposition to the Iraq war, will be able to tell voters as he confronts a difficult re-election campaign that he has overseen the promised end to the Iraq conflict.

Although foreign policy does not rank high in voters’ minds at a time of economic stress at home, Obama used his appearance Friday to showcase some of his accomplishments in winding down expensive wars and killing declared enemies.

Obama noted that, after the initial troop surge he authorized in Afghanistan, he is withdrawing forces from that decade-old battlefield. He recalled the killing of Osama bin Laden in May and the “definitive end” of Moammar Gadhafi’s long, erratic rule in Libya.

“So to sum up, the United States is moving forward from a position of strength,” Obama said before shifting the focus of his brief remarks to the economy.

“Because 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,” he said.

The plan conforms with the agreement negotiated by the Bush administration to withdraw U.S. forces from Iraq at the end of 2011, something that many of Obama’s Republican rivals failed to note in statements criticizing the complete withdrawal.

Among them was Mitt Romney, a front-runner for the nomination who has staked out a hawkish foreign policy position. In a statement, Romney said that the “astonishing failure to secure an orderly transition in Iraq has unnecessarily put at risk the victories that were won through the blood and sacrifice of thousands of American men and women.”

Obama administration officials and Maliki’s government have focused on how many U.S. troops should stay to continue training Iraqi national forces and monitoring potential flash points, such as the boundary between the Kurdish north and the rest of Iraq.