President Obama will withdraw all U.S. forces 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 reelection 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 reelection 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 Gaddafi’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.

“Our forces are good, but not to a sufficient degree that allows them to face external and internal challenges alone,” Col. Salam Khaled of the 6th Brigade of the Iraqi army said Friday. “The loyalty of forces is not to their homeland. The loyalty is to the political parties and to the sects.”

Administration officials said Iraqi forces are indeed prepared to preserve the nation’s stability.

“One assessment after another about the Iraqi security forces came back saying these guys are ready, these guys are capable, these guys are proven,” Denis McDonough, the deputy national security adviser, told reporters.

Obama’s announcement came as Turkey engaged in counteroffensive strikes against Kurdish rebels in the semiautonomous Kurdish region of northern Iraq. The action is supported by NATO and the United States.

In the case of the Kurdish region, the U.S. troop withdrawal could be positive “because [the Americans] are helping Turkey in the aggression,” independent Iraqi lawmaker Mahmoud Othman, who is from the region, said in a phone interview. “So maybe it’s better for them not to be around.”

In a statement this week, factional leader Moqtada al-Sadr, a Shiite cleric who strongly opposes the U.S. presence in Iraq, said that there must first be a complete withdrawal and that training would be allowed “only if a new agreement has been concluded once the withdrawal is completed and the oppressed Iraqi people are financially compensated.”

Earlier this year, as concerns mounted over ongoing insurgent strikes and Iranian influence in Iraq, the administration made clear its willingness to continue tasks such as training, air defense, intelligence and reconnaissance, and joint counterterrorism missions.

Throughout the summer, the White House urged the Iraqis to come up with a list of tasks they would like U.S. forces to continue and informally spoke of leaving between 3,000 and 10,000 troops behind.

Ultimately, minority Kurdish and Sunni leaders pressed for an agreement that would allow U.S. troops to remain. But Sadr and other opponents continued to oppose a deal, and the talks finally faltered on the immunity question.

“We will continue discussions on how we might help Iraq train and equip its forces — again, just as we offer training and assistance to countries around the world,” Obama said. “After all, there will be some difficult days ahead for Iraq, and the United States will continue to have an interest in an Iraq that is stable, secure and self-reliant.”

Staff writer Dan Zak in Baghdad and special correspondent Uthman al-Mokhtar in Fallujah contributed to this report.