By Missy Ryan and Patrick Markey
BAGHDAD (Reuters) - U.S. forces formally ended almost nine years of war in Iraq on Thursday with a modest flag-lowering ceremony in Baghdad, while to the north flickering violence highlighted ethnic and sectarian strains threatening the country in years ahead.
"After a lot of blood spilled by Iraqis and Americans, the mission of an Iraq that could govern and secure itself has become real," Defense Secretary Leon Panetta said at the ceremony at Baghdad's still heavily-fortified airport.
Almost 4,500 U.S. soldiers and tens of thousands of Iraqis lost their lives in the war that began with a "Shock and Awe" campaign of missiles pounding Baghdad and descended into sectarian strife and a surge in U.S. troop numbers.
U.S. soldiers lowered the flag of American forces in Iraq and slipped it into a camouflage-colored sleeve in a brief outdoor ceremony, symbolically ending the most unpopular U.S. military venture since the Vietnam War of the 1960s and 70s.
The remaining 4,000 American troops will leave by the end of the year.
Toppled Iraqi dictator Saddam Hussein is dead, executed in 2006, and the worst sectarian violence has, at least for now, passed. But Iraq still struggles with insurgents, a fragile power-sharing government and an oil-reliant economy plagued by power shortages and corruption.
"Iraq will be tested in the days ahead, by terrorism, by those who would seek to divide, by economic and social issues," Panetta told the rows of assembled U.S. soldiers and embassy officials at the ceremony. "Challenges remain, but the United States will be there to stand by the Iraqi people."
In Falluja, the former heartland of an al Qaeda insurgency that suffered some of the most vicious fighting in the war, several thousand Iraqis celebrated the withdrawal on Wednesday, some burning U.S. flags and waving pictures of dead relatives.
Falluja became more than any other Iraqi city a symbol for the brutality of the war after the 2003 invasion.
Ali al-Falluji's building lies with its ceiling collapsed, debris scattered across a Falluja roadside just as the Iraqi businessman left it in 2004 when U.S. bombs punctured its roof. "This scene must remain like it is as a testimony to the brutality of the Americans," said Falluji.
It took two U.S. incursions into Falluja in 2004, and weeks of devastating house-to-house fighting, to subdue the city.
"I feel how my son Ibrahim grieves. He was injured in his head by a U.S. bullet in April 2004 and it paralyzed him," said Mudhafer Ali, a Falluja retiree. "The Americans have left, but they left us for our sorrow, pains and destroyed the future."
Elsewhere, around 2,500 mainly Shi'ite Muslim residents of the northern territory of Diyala protested in front of the provincial council building for a second day against a move to declare autonomy from mainly Sunni Muslim Salahuddin province.
Police used batons and water cannon to disperse demonstrators who tried to storm the council headquarters, witnesses said. Some protesters climbed to the roof of the building and raised green and black Shi'ite flags.
Some parts of Diyala are territories disputed between the minority Kurds in the north and the Arab, Shi'ite-led government in Baghdad. The long-standing row over land, oil and power could trigger further conflict in Iraq after American troops depart.
Iraq's neighbors will watch how Baghdad tackles its sectarian and ethnic division without the U.S. military. Events there could be influenced by conflict in neighboring Syria that has taken on a sectarian hue in recent weeks.
U.S. President Barack Obama, who made an election promise in 2008 to bring troops home from Iraq, told Iraqi Prime Minister Nuri al-Maliki that Washington will remain a loyal partner after the last troops roll across the Kuwaiti border.
"WE NEED TO BE SAFE"
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 without U.S. troops.
"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."
Some like Saad fear more sectarian strife or an al Qaeda return to the cities.
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 that U.S. officials say are backed by Iran.
But attacks now target local government offices and security forces in an attempt to show the authorities are not in control.
Saddam Hussein's fall opened the way for the Shi'ite majority community to take positions of power after decades of oppression under his Sunni-run Baath party.
Even the power-sharing in Maliki's government is hamstrung, with coalition parties split along sectarian lines, squabbling over laws and government posts.
Sunnis fear they will be marginalized or even face creeping Shi'ite-led authoritarian rule under Maliki. A recent crackdown on former members of the Baath party has fuelled those fears.
Iraq's Shi'ite leadership frets that the crisis in nearby 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 but talks about 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 to push through parliament.
At the height of the war, 170,000 American soldiers occupied more than 500 bases across Iraq.
Only around 150 U.S. soldiers will remain after December 31, attached to the huge U.S. Embassy near the Tigris River. Civilian contractors will take on the task of training Iraqi forces on U.S. military hardware.
Every day trucks with troops trundle in convoys across the border into Kuwait.
"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)