By Missy Ryan and Patrick Markey
(Reuters) - The U.S. military officially ended its war in Iraq on Thursday, packing up a military flag at a ceremony with U.S. Defense Secretary Leon Panetta nearly nine years after the invasion that ousted Saddam Hussein.
The last 4,000 American troops will withdraw by the end of the year, leaving Iraq still tackling a weakened but stubborn insurgency, sectarian tensions and political uncertainty.
"After a lot of blood spilled by Iraqis and Americans, the mission of an Iraq that could govern and secure itself has become real," Panetta said at the ceremony.
U.S. soldiers rolled up the flag for American forces in Iraq and slipped it into a camouflage-colored sleeve.
Nearly 4,500 U.S. soldiers and tens of thousands of Iraqis lost their lives in a war that began with a "Shock and Awe" campaign of missiles pounding Baghdad, but later descended into a bloody sectarian struggle between long-oppressed majority Shi'ites and their former Sunni masters.
Saddam is dead, an uneasy politics is at work and the violence has ebbed. But Iraq still struggles with the insurgency, a fragile power-sharing government and an oil-reliant economy plagued by power shortages and corruption.
In Falluja, the former heartland of an al Qaeda insurgency and scene of some of the worst fighting in the war, several thousand Iraqis celebrated the withdrawal on Wednesday, some burning U.S. flags and waving pictures of dead relatives.
Iraq's neighbors will keep a close watch on how Baghdad will confront its problems without the buffer of a U.S. military presence, while a crisis in neighboring Syria threatens to upset the region's sectarian and ethnic balance.
President Barack Obama, who made an election promise to bring troops home, told Iraqi Prime Minister Nuri al-Maliki that Washington will remain a loyal partner after the last troops roll across the Kuwaiti border.
Iraq's Shi'ite leadership presents the withdrawal as a new start for the country's sovereignty, but many Iraqis question which direction the nation will take once U.S. troops leave.
Some fear more sectarian strife or an al Qaeda return to sow terror in the cities. A squabble between Kurds in their northern semi-autonomous enclave and the Iraqi Arab central government over disputed territories and oil is another flashpoint.
Violence has ebbed since the bloodier days of sectarian slaughter when suicide bombers and hit squads claimed hundreds of victims a day at times as the country descended into tit-for-tat killings between the Sunni and Shi'ite communities.
In 2006 alone, 17,800 Iraqi military and civilians were killed in violence.
Iraqi security forces are generally seen as capable of containing the remaining Sunni Islamist insurgency and the rival Shi'ite militias U.S. officials say are backed by Iran.
But even for those enjoying a sense of sovereignty, security is still a major worry. Attacks now target local Iraqi government offices and security forces in an attempt show that the authorities are not in control.
"I am happy they are leaving. This is my country and they should leave," said Samer Saad, a soccer coach. "But I am worried because we need to be safe. We are worried because all the militias will start to come back."
The fall of Saddam opened the way for Iraq's Shi'ite majority community to ascend to positions of power after decades of oppression under his Sunni-run Baath party. But nine years after the invasion Iraq remains a splintered country, worrying many that the days of sectarian slaughter are not over.
Even the political power-sharing in Maliki's Shi'ite-led government is hamstrung by sectarian divides. The government at times seems paralyzed as parties split along sect lines, squabbling over key laws and government posts.
Sunni Iraqis fear marginalization or even a creeping Shi'ite-led authoritarian rule under Maliki. A recent crackdown on former members of the Baath party has fueled those fears.
Sectarian divisions leave Iraq vulnerable to meddling by neighbors trying to secure more influence, especially as Sunni-controlled Arab nations view Iranian involvement as an attempt to control Iraq's Shi'ite parties at the cost of Sunnis.
Iraq's Shi'ite leadership frets the crisis in neighboring Syria could eventually bring a hardline Sunni leadership to power in Damascus, worsening Iraq's own sectarian tensions.
"WAS IT WORTH IT?"
U.S. troops were supposed to stay on as part of a deal to train the Iraqi armed forces. Washington had asked Iraq for at least 3,000 troops to remain in the country. But talks over immunity from prosecution for American soldiers fell apart.
Memories of U.S. abuses, arrests and killings still haunt many Iraqis and the question of legal protection from prosecution looked too sensitive for Iraq's political leadership to push through a splintered parliament.
At the height of the war, 170,000 American soldiers occupied more than 500 bases across the country. Now only two bases and 5,500 troops remain in the country. All will be home before the end of the year when a security pact expires.
Only around 150 U.S. soldiers will remain in Iraq after December 31 attached to the huge U.S. Embassy that sits near the Tigris River. Civilian contractors will take on the task of training Iraqi forces on U.S. military hardware.
Every day hundreds of trunks and troops trundle in convoys across the Kuwaiti border as U.S. troops end their mission.
"Was it worth it? I am sure it was. When we first came in here, the Iraqi people seemed like they were happy to see us," said Sgt 1st Class Lon Bennish, packing up recently at a U.S. base and finishing the last of three deployments in Iraq.
"I hope we are leaving behind a country that says 'Hey, we are better off now than we were before.'"
(Editing by David Stamp)
Timeline: The U.S. war in Iraq
Get top stories and blog posts emailed to me each day. Newsletters may offer personalized content or advertisements. Learn more