This post has been updated. See note at bottom for details.
REPORTING FROM BAGHDAD -- The U.S. military mission in Iraq formally ended Thursday in a small ceremony at Baghdad airport as the last U.S. troops prepared to leave the country after nearly nine years of war, billions of dollars spent and nearly 4,500 American lives lost.
Defense Secretary Leon E. Panetta and other top civilian and military officials flew in to Baghdad to mark the formal end of the U.S. military effort, one of most divisive wars in American history.
Instead of addressing the deep questions about the war, Panetta paid tribute to U.S. troops, arguing that the combat losses and the enormous expenditure of resources since 2003 had not been wasted.
"To be sure, the cost was high -- in blood and treasure for the United States and for the Iraqi people," he told the audience of around 200 troops and a few Iraqi officials. "But those lives were not lost in vain -- they gave birth to an independent, free and sovereign Iraq."
Yet an atmosphere of uncertainty permeates the U.S. exit.
Though security has improved dramatically since the insurgency's height in 2006 and 2007, Iraq remains riven by ethnic and sectarian divisions and beset by fears that the U.S. departure will cause violence to increase once again.
Many U.S. military officers, including some in attendance Thursday, have spent years fighting in Iraq and now wonder as they leave what has been achieved.
In the 45-minute ceremony, Gen. Ike Austin, commander of U.S. forces in Iraq, furled his flag, terminating his command.
He recalled giving the command that sent the 3rd Infantry Division into Iraq in 2003 and the surge of U.S. forces in 2007 that helped stop the war's "downward spiral."
There was no mention during the ceremony of Saddam Hussein's pursuit of weapons of mass destruction or his ties to Al Qaeda -- the Bush administration's largely discredited reasons for invading Iraq in 2003.
Only two U.S. bases and around 4,000 troops remained in Iraq as of Thursday, the rear guard of a force that was more than 170,000 strong at the height of the war and once controlled hundreds of bases.
The last military personnel under Austin's command will depart Iraq by the weekend, officials said.
There was perhaps no better symbol of the fragility of the security gains in Iraq than that the final ceremony was held in a structure known as the "Glass House."
The domed, glass-clad structure near the Baghdad airport runway was once a VIP lounge under Hussein. Many of the glass panels were shattered and its reception rooms lay in ruins after U.S. troops stormed the airport in 2003, but even today the building is patched with plywood and camouflage netting, and protected behind blast walls.
Around 200 U.S. military personnel will remain in Iraq after this year, but only to administer arms sales and other limited military exchanges as members of the U.S. diplomatic mission.
For the administration, the departure fulfills President Obama's pledge to end U.S. military involvement in Iraq, a move that polls suggest is supported by many Americans.
Many officers and even some Iraqis were upset by the Obama administration's decision in October to break off talks with Iraq on keeping U.S. forces there, fearing Iraq would slide back into chaos.
Obama administration officials said it was time for Iraq's government to take full responsibility for the country's security.
Obama, who as a candidate once called the Iraq conflict a "dumb war," broke off talks with Iraq in October on keeping troops there after the two sides were unable to agree on giving U.S. troops legal immunity from Iraqi prosecution.
White House officials were never eager to keep U.S. troops in Iraq, fearing it would sully Obama's claim to be wrapping up the war. But they now face the risk that Iraq's ethnic and sectarian violence will reemerge, and that neighboring Iran will gain influence as the U.S. pulls back.
"Let me be clear: Iraq will be tested in the days ahead -- by terrorism and by those who would seek to divide," Panetta said.
But the Obama administration has adopted its own version of the Bush administration claim that the conflict was worth the cost because it helped free Iraq from Hussein.
Panetta and Austin were joined by Ambassador James Jeffrey and Army Gen. Martin Dempsey, chairman of the Joint Chiefs of Staff. Dempsey was the commander of the 1st Armored Division in 2006 when Sunni-Shiite violence erupted in and around Baghdad, leading to the toughest fighting of the war.
"We paid a great price here and it was a price worth paying," Dempsey said.
[Updated, 10:06 a.m. Dec. 15: The opening paragraph of this post has been updated to clarify that the nearly 4,500 killed in the Iraq War refers to the number Americans killed, not the war's total death toll.]
-- David S. Cloud
Photo: The flag for the U.S. mission in Iraq is displayed before being retired during a casing ceremony Thursday at the former Sather Air Base in Baghdad. Credit: Mario Tama / Getty Images