One of the last American units in Baghdad, the 1st Cavalry Squadron, 73rd Infantry-82nd Airborne, provided security for the ceremony, its last mission. Apache attack helicopters provided air cover for the ceremony.
"This outcome was never certain, especially during the war's darkest days," Panetta said. "Today, some five years later, and after a lot of blood spilled by Iraqis and Americans, the mission of an Iraq that could govern and secure itself has become real. The Iraqi army and police have been rebuilt, violence levels are down, al Qaeda weakened, rule of law strengthened, educational opportunities expanded and economic growth expanding.
"To be sure, the cost was high, in blood and treasure for the United States, and for the Iraqi people," he added. "Those lives were not lost in vain. They gave birth to an independent, free and sovereign Iraq."
Dempsey also said the fight in Iraq was worth it. "We've paid a great price here, and it's a price worth paying," he said.
Gen. Lloyd Austin, the commander of U.S. Forces Iraq, said today's ceremony was especially poignant for him because he recalled having given the order for U.S. troops to enter Iraq in the 2003 invasion and now he was seeing them leave.
"[This is now] an Iraq with whom the U.S. will continue to work with in every way possible," U.S. Ambassador to Iraq Jim Jeffrey said.
While the U.S. military presence in Iraq will cease to exist, America's diplomatic presence will be the largest in the world. About 16,000 embassy staff and security contractors will remain at what is already one of the largest U.S. embassies.
Panetta warned that the U.S .departure might not be without security pitfalls.
"Let me be clear: Iraq will be tested in the days ahead, by terrorism, and by those who would seek to divide it, by economic and social issues, by the demands of democracy itself," Panetta said. "We will continue to help Iraq address violent extremism and defend against external threats. We will continue to have a robust and enduring military presence across the Middle East."
The forces still in Iraq will soon make their way to Kuwait and then transition back home. "The vast majority by far will be home by the holidays," a senior defense official said.
But another senior defense official says that some of the troops departing Iraq will remain behind in Kuwait for a period of time, probably less than an Army brigade.