The U.S. military officially ended its war in Iraq on Thursday packing up a military flag at a ceremony with U.S. Defence 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.

(Reporting by Missy Ryan; writing by Patrick Markey)