WASHINGTON (AFP) - US President Barack Obama said all American troops will leave Iraq by the end of the year, ending a long war which cleaved deep political divides and estranged the United States from its allies. The decision, announced Friday, came after Iraq failed to agree to legal immunity for a small residual force that Washington had hoped to keep in the country to train the army and counter the influence of neighbouring Iran, officials said. After nearly nine years, the deaths of more than 4,400 US troops, tens of thousands of Iraqis and the expenditure of hundreds of billions of dollars, Obama said the last American soldier would leave with his head held high. Today I can report that, as promised, the rest of our troops in Iraq will come home by the end of the year. After nearly nine years, Americas war in Iraq will be over, Obama said at the White House. Our troops in Iraq will definitely be home for the holidays, said Obama, who rose to power in opposing the unpopular war and pledged as a presidential candidate to withdraw all US military personnel. In his weekly radio address Saturday, Obama added that his decision to pull all US troops out of Iraq by the end of the year and the death of former Libyan leader Moamer Gaddafi were reminders of 'renewed American leadership in the world. Obama announced the pullout after holding a video conference with Prime Minister Nuri al-Maliki, which US officials said included a moving tribute by the Iraqi leader to American troops who died in his country. US defence officials said talks on a future military mission had collapsed over the question of legal protections for American troops. That is a red line for us, said one official, who spoke on condition of anonymity. Obama said that despite the failure, US defence officials would still seek ways to help train Iraqi forces, as they do for many other nations. And hours later, US Defence Secretary Leon Panetta confirmed such a strategy. Once weve completed the reduction of the combat presence, then I think we begin a process of negotiating with them, Panetta told reporters. We now turn our full attention to pursuing a long-term strategic partnership with Iraq thats based on mutual interest and mutual respect, he added. Maliki, whom Obama has invited to the White House in December, said in a brief statement that the two leaders were on the same page on the withdrawal. The 39,000 remaining US troops in Iraq must pull out by the end of 2011 under an accord between the two countries reached during the Bush presidency. Republican presidential candidate Mitt Romney accused Obama of presiding over an astonishing failure to secure an orderly transition in Iraq which put at risk victories won through the sacrifice of American soldiers. 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, he said. Republican Senator Lindsey Graham of South Carolina, one of the staunchest supporters of the war, said he feared that this decision has set in motion events that will come back to haunt our country. Democrats largely supported Obamas move. Senator John Kerry said Washington was fulfilling its obligations to a nation that wanted to chart its own future. The US withdrawal provokes a number of questions about the war-ravaged countrys future, including: - Are the Iraqi military and security forces up to the job of safeguarding security gains made over recent years? - How will Iran seek to expand its influence in Iraqi politics? - Is Iraqs fledgling political system robust enough to survive? - Will disputes between Kurdistan and Baghdad drive a deeper wedge between the autonomous region and the central government? Obama administration officials declined to say whether the war had been worthwhile. History is going to have to judge that, said Vice President Joe Bidens national security advisor Tony Blinken, who argued that vibrant politics in Iraq would be part of the US legacy.