(CNN) -- President Barack Obama on Friday announced that virtually all U.S. troops will come home from Iraq by the end of the year -- at which point he can declare an end to America's long and costly war in that Middle Eastern nation.
"After nearly nine years, America's war in Iraq will be over," Obama said. "The coming months will be a season of homecomings. Our troops in Iraq will definitely be home for the holidays."
Of the 39,000 troops in Iraq, about 150, a negligible force, will remain to assist in arms sales, a U.S. official told CNN. The rest will be out of Iraq by December 31.
The president said he was making good on his 2008 campaign pledge to end a war that has divided the nation since it began in 2003 and claimed more than 4,400 American lives.The announcement also came after talks that might have allowed a continued major military presence broke down amid disputes about whether U.S. troops would be immune to prosecution by Iraqi authorities.
Obama spoke with Iraqi President Nuri al-Maliki in a video conference Friday, after which he said both nations were comfortable with the decision on how to move forward.
The new partnership with Iraq will be "strong and enduring," Obama said.
"The last American soldier will cross the border out of Iraq with their head held high, proud of their success and knowing that the American people stand united in our support for our troops," Obama said.
According to a statement from the Iraqi prime minister's office, al-Maliki and Obama "shared the same point of view on the need to start a new phase of strategic relations." That includes agreeing to a high-level meeting within two weeks.
Beyond the human cost, the price tag for U.S. military activity in Iraq has been steep as well.
A report from the non-partisan, government-funded Congressional Research Service found that the Defense Department spent nearly $757 billion for military operations in Iraq over the past decade, $50 billion higher than the estimate released by the Pentagon. Another $41 billion for Iraq was spent on State Department and USAID initiatives, plus $6 billion for troops' health expenses, the CRS report stated.
Paul Rieckhoff -- an ex-Army soldier who heads the Iraq and Afghanistan Veterans of America, the first and largest such organization for these veterans, according to its website -- cheered Friday's announcement as "really good news for the troops serving overseas."
"It's a really poignant time, especially for the veterans community," Rieckhoff told CNN. "Many of us gave large parts of our lives, some gave all in support of Operation Iraqi Freedom and Operation New Dawn."
While Democrats largely applauded Friday's announcement, some Republicans disagreed with the president. Sen. John McCain called it a "consequential failure" for the Obama administration, which he said wasn't focused on succeeding in Iraq, and Iraq's government.
"Today marks a harmful and sad setback for the United States in the world," said McCain, an Arizona Republican who faced off against Obama in the 2008 presidential election. "This decision will be viewed as a strategic victory for our enemies in the Middle East, especially the Iranian regime, which has worked relentlessly to ensure a full withdrawal of U.S. troops from Iraq."
Deputy National Security Adviser Denis McDonough dismissed the notion that Friday's decision would affect Iran, which he claimed already is "weaker and more isolated" due to U.S. and allied efforts unrelated to Iraq.
"We don't need to try to exercise our influence on those matters through Iraq," McDonough told reporters Friday. "We're obviously concerned about Iran's willingness to live up to its obligations ... but we don't have concerns about our ability to make sure that the Iraqis can exercise the kind of sovereignty that they want."
Another U.S. official -- who is not authorized to speak for attribution -- acknowledged that "the Iranians have been trying to gain influence in Iraq for some time," but stressed that "Iranian influence in Iraq has limits." The official said the Iraq "will not roll over" to Iran, with whom it has a long history of border disputes including a bloody eight-year war in the 1980s.
The current Status of Force Agreement had called for U.S. troops to leave by the end of 2011. But lengthy negotiations in recent months had led some to expect that American troops -- roughly 40,000 of which are in Iraq -- would remain there into next year.
These talks, however, broke down over the prickly issue of legal immunity for U.S. troops in Iraq, a senior U.S. military official with direct knowledge of the discussions told CNN this month.
U.S. Defense Secretary Leon Panetta and other top brass have repeatedly said any deal to keep U.S. troops in Iraq beyond the withdrawal deadline would require a guarantee of legal protection for American soldiers.
But the Iraqis refused to agree to that, opening up the prospect of Americans being tried in Iraqi courts and subjected to Iraqi punishment.
The negotiations were strained following WikiLeaks' release of a diplomatic cable that alleged Iraqi civilians, including children, were killed in a 2006 raid by American troops rather than in an airstrike as the U.S. military initially reported.
U.S. troops have already started the drawdown. For instance, a brigade from Fort Bliss, Texas, that was originally scheduled to be among the last to leave Iraq was being pulled out of the country months ahead of its planned departure, military officials told CNN last week.
Besides withdrawing more units, others will not head overseas as planned. That includes about 775 Georgia-based soldiers from the Army's 3rd Infantry Division, which announced Friday it will not deploy to Iraq in December as previously scheduled.
Gen. Lloyd J. Austin III, commander of U.S. forces in Iraq, has said that Iraq wouldn't be able to defend its borders if U.S. troops pulled out and also questioned Iraqi forces ability to defend its airspace. But Panetta, en route to Indonesia, said history shows that Iraq will be ready.
"We've taken out now about 100,000 troops and yet the level of violence has remained relatively low," the defense secretary said. "And I think that's a reflection of the fact that the Iraqis have developed a very important capability here to be able to respond to security threats within their own country."
Regardless, officials insisted that the drastic pullback of troops does not mean an end to the U.S. government's presence in Iraq.
State Department spokesman Mark Toner described Friday's development as the start of "a new chapter in our relationship" with Iraq -- while acknowledging the challenges of the change.
"You can't flip a switch and go from a military operation to a civilian operation; there has to be a transition and we're working on that transition," he said. "But we believe we're ready."
Toner also noted substantial improvements in the capabilities of the Iraqis, even as he admitted the continued importance of addressing "security needs" of the hundreds of nonmilitary U.S. personnel who will remain there.
That includes about 1,700 diplomats, law enforcement officers and various economic, agriculture and other professionals and experts who will be in Iraq into 2012, according to the State Department. In addition, 5,000 security contractors will protect the U.S. diplomats and another 4,500 contractors will serve other roles, such as helping provide food and medical services, until they can be done locally.
Toner said the U.S. and Iraqi governments are still talking about security and other matters, though he stressed any such discussions should not change the basic decision announced Friday.
"We continue to talk about the post-December 31 arrangement (and) security relationship," Toner said. "At the same time, we are very committed to meeting the December 31 deadline."
Panetta, too, did not rule out the possibility that U.S. forces would head to Iraq to train forces there.
"As we ... look at developing this normal relationship, a lot of it is going to depend on what they want, what their needs are and how we can best meet them," he said.
CNN's Chris Lawrence, Jamie Crawford and Pam Benson contributed to this report.