The military of the Ottoman Empire remained an effective fighting force until the second half of the eighteenth century when it suffered a catastrophic defeat against Russia in the 1768-74 war. Selim III came to the throne with an ambitious effort for military reforms in 1789. He failed and was replaced by Mahmud II in 1808 who established martial law through Alemdar Mustafa Pasha. At first he allied with the Janissaries to break the power of the provincial governors and then turned on the Janissaries and removed them altogether during the 1826 Auspicious Incident. Efforts for a new system (1826–1858) began following the Auspicious incident.