After a period of stagnation, and military defeat Algiers was severely weakened. After losing the Barbary Wars, and the Bombardment of Algiers, the Odjak sprung into action and killed the ruling dey, Omar Agha. In 1817 Ali Khodja couped the country following a decisive defeat. The Turk janissaries attempted a coup, against whom Ali Khodja raised the Kouloughli Janissaries, and allied berber tribes such as the Igawawen. The Turks were defeated and slaughtered while the rest were sent back to the Ottoman provinces.