Many colonial wars end badly. Here are a few bad endings:
1) Columns of retreating colonial forces cut to pieces by vengeful locals. examples: first Afghan War. Napoleon's retreat from Moscow. 6th Army in Stalingrad.
2) Colonial army trapped in garrison and slaughtered or surrender. examples: Dien Bien Phu. Khartoum. Al Kut.
3) strong Colonial army assault a local stronghold and are bloodily defeated. examples: Teutoberg Forest. Battle of New Orleans. The shocked imperial power settles for a defeat.
what then will happen in Iraq as the US is finally defeated as now seems probable?
Because the US has massive airpower, a retreating army could get out without being slaughtered or forced into a humiating surrender. The perimeter of any isolated garrison could be defended as well. Airpower scatters the forces that could concentrate to overrun a US base.
Case three is the most likely outcome. The intransigent nature of the Bush admin will I think, demand one last set piece battle in Iraq. Some proof that the US remains master of the field of battle in the conventional sense. A victory to have before the negotiated end, one last gamble. A single city to be beseiged and obliterated. I think the US will be bloodily repulsed when this battle occurs. The Iraqis will dig in and show what they are capable of and the US will bow and exit.
Case three has arguably happened already. Iraq bore the full brunt of the US Army in a set piece assault and has amazingly continued fighting longer than Germany and Japan in WW2. But Bush will require one last show of phoney dominance before the war is finally settled. A section of Sadr city or a small Suni city around baghdad will be singled out and the end game will play itself out.