At one point, his defeat seemed imminent. Now he presides over a ruined country. How did this happen?