The Mexican War of Independence was fought from 16 September 1810 to 27 September 1821 when the native-born criollo elite of New Spain launched a war of national liberation against the Spanish, fighting for the independence of the new state of Mexico. The war occurred during the greater South American Wars of Liberation.
Spanish rule in Mexico had existed since 1521, but New Spain had been granted a degree of autonomy as a viceroyalty. A criollo (white Spaniard) elite came to dominate the country, and, during the late 18th century, the educated elite was inspired by the Enlightenment, the American Revolutionary War, the French Revolution, and the Spanish monarchy's centralizing "Bourbon Reforms" to seek independence from Spain. In 1808, the Spanish Bourbon monarchy was ousted from power by Napoleon I of France at the start of the Peninsular War, and, that same year, the city council of Mexico City claimed sovereignty in the absence of a legitimate king. This led to a coup against the Spanish viceroy Jose de Iturrigaray, who suppressed the uprising and jailed its leaders. However, small groups of rebels met in other cities of New Spain to raise movements against colonial rule. On 16 September 1810, the secular Catholic priest Miguel Hidalgo called the peasants and indigenous inhabitants of Dolores, Guanajuato to action in the famous "Cry of Dolores", and rebels from Queretaro joined them shortly after.
The rebellion initially disputed the legitimacy of the French-installed Spanish monarch Joseph Bonaparte while recognizing the sovereignty of King Ferdinand VII of Spain over Spain and its colonies, but its leaders went on to reject the Spanish claim and espouse a new social order, including the abolition of slavery. The rebellion's prospects of success were initially dim, as Hidalgo, Ignacio Allende, and other major leaders were captured and executed in 1811. Jose Maria Morelos then took over the leadership of the revolution, capturing Cuautla, Oaxaca, and Acapulco in 1812. On 6 November 1813, he convened the Congress of Chilpancingo to sign the first official document of independence. In 1815, Morelos himself would be captured and executed for treason.
From 1815 to 1821, the only resistance to Spanish rule came from small guerrilla bands, and Guadalupe Victoria of Puebla and Vicente Guerrero of Oaxaca emerged as the revolution's new leaders. In December 1820, the Spanish viceroy Juan Ruiz de Apodaca sent out one last expedition to crush the faltering rebellion, with Agustin de Iturbide commanding the army. The conservative criollo Iturbide was committed to the defense of property rights and social privileges, but he resented his lack of promotion and failure to gain wealth. The rise of the Trienio Liberal in Spain in 1821 and the overthrow of King Ferdinand's conservative regime by Spanish liberals led to the conservative Royalists in the Americas ironically deciding to join the revolution against the now-liberal Spanish regime. Iturbide joined forces with Guerrero's insurgent army, and Iturbide proclaimed three guarantees for Mexican independence from Spain in Iguala: Mexico would become an independent monarchy, criollos would be given equal rights and privileges as Spanish-born peninsulares, and the Catholic Church would retain its privileges and its status as the official religion of Mexico. Iturbide's army was joined by rebels from all across Mexico, causing the Viceroy to resign rather than face more bloodeshed. On 24 August 1821, representatives of the Spanish crown and Iturbide signed the Treaty of Cordoba, recognizing Mexican independence.
On 27 September 1821, Iturbide's army entered Mexico City, and, the following day, he proclaimed the independence of the First Mexican Empire. Half of the new government employees appointed were Iturbide's followers, and, on the night of 18 May 1822, a mass demonstration by the Regiment of Celaya marched through the streets of Mexico City and demanded that Iturbide accept the throne. The following day, Iturbide was declared Emperor of Mexico, and Iturbide dissolved the Congress on 31 October 1822 and replaced it with a sympathetic junta. Spanish attempts to reconquer Mexico would continue until 1829.