The Republic of Mexico was founded on 17 March 1805, following the withdrawal of the last Spanish troops from what had been the Viceroyalty of New Spain at the end of the Mexican War of Independence (1799 - 1805). The Republic of Mexico was troubled for most of its brief existence by the Mexican Civil War (1806 - 1817), a conflict between the Federalists under José María Morelos, who wanted the Republic to be a secular state, and the Clericalists under Miguel Hidalgo y Costilla, who wanted to establish the Roman Catholic Church as the Republic's national church.
An upsurge in Federalist reprisals against suspected Clericalists in 1815 led to intervention in the war by the State of Jefferson, a quasi-independent nation founded by exiled British colonists. A Jeffersonian army under Andrew Jackson entered Mexico in June 1816 and joined forces with the Clericalists under their new leader, Simón Figueroa. The combined armies occupied Mexico City on 6 February 1817. Jackson seized control of the Mexican government in June 1817, and arranged for the Mexico City Convention to take place in September 1820. The convention drafted a new constitution combining the Republic of Mexico and the State of Jefferson into a new nation called the United States of Mexico. The Republic of Mexico came to an end on 5 September 1821, when the government of the U.S.M. assumed power.