BAGHDAD—After nearly nine years of war, tens of thousands of casualties—including 4,500 dead—and more than $800 billion spent, the U.S. military on Thursday formally ended its mission in Iraq and prepared to leave the country.

For years, commanders in Iraq have handed off to their successors the top call sign, Lion 6, along with the American battle flag adorned with a Mesopotamian sphinx. But on Thursday, in a tradition-drenched ceremony with Defense Secretary Leon Panetta looking on, the current Lion 6, Army Gen. Lloyd Austin, pulled down the colors and cased them for a return to the U.S.

No words, no ceremony, can provide full tribute to the sacrifices that brought this day to pass,” Mr. Panetta said.

In the coming days, the last of the 4,000 U.S. military personnel still in Iraq will follow the flag and head home—leaving fewer than 200 to serve as part of the diplomatic mission. The military has largely shuttered its main base in eastern Baghdad, Camp Victory—a name that often had a bitterly ironic ringfor many service members—and the final ceremony occurred at Baghdad International Airport, known to the more than a million grunts who deployed to Iraq by its awkward acronym BIAP.

Follow this link to read more: