quality:correction, structural:scholar_edition
Independence era (1808–1855)

The upheaval in the Spanish Empire that resulted in the independence of most of its New World territories was due to Napoleon Bonaparte 's invasion of Spain in 1808. On 16 September 1810, secular priest Miguel Hidalgo y Costilla declared against "bad government" in the small town of Dolores, Guanajuato. This event, known as the Cry of Dolores (Spanish: Grito de Dolores) is commemorated each year, on 16 September, as Mexico's independence day. Hidalgo and some of his soldiers were eventually captured, Hidalgo was defrocked, and they were executed by firing squad on 31 July 1811. The first 35 years after Mexico's independence were marked by political instability and the changing of the Mexican state from a transient monarchy to a fragile federated republic. There were military coups d'état, foreign invasions, ideological conflict between Conservatives and Liberals, and economic stagnation.

Former Royal Army General Agustín de Iturbide became regent, as newly independent Mexico sought a constitutional monarch from Europe. When no member of a European royal house desired the position, Iturbide himself was declared Emperor Agustín I. The United States was the first country to recognize Mexico's independence, sending an ambassador to the court and sending a message to Europe via the Monroe Doctrine not to intervene in Mexico. The emperor's rule was short (1822–1823) and he was overthrown by army officers in the Plan of Casa Mata. After the forced abdication of the monarch, Central America and Chiapas left the union to form the Federal Republic of Central America. In 1824, the First Mexican Republic was established. Former insurgent General Guadalupe Victoria became the first president of the republic — the first of many army generals to hold the presidency. In 1829, former insurgent general and fierce Liberal Vicente Guerrero, a signatory of the Plan of Iguala that achieved independence, became president in a disputed election. During his short term in office, from April to December 1829, he abolished slavery. His Conservative vice president, former Royalist General Anastasio Bustamante, led a coup against him and Guerrero was judicially murdered.

Mexico's ability to maintain its independence and establish a viable government was in question. Spain attempted to reconquer its former colony during the 1820s but eventually recognized its independence. France attempted to recoup losses it claimed for its citizens during Mexico's unrest and blockaded the Gulf Coast during the so-called Pastry War of 1838–1839. General Antonio López de Santa Anna emerged as a national hero because of his role in both these conflicts; Santa Anna came to dominate the politics for the next 25 years, often known as the "Age of Santa Anna", until his overthrow in 1855.

Mexico also contended with indigenous groups that controlled the territory that Mexico claimed in the north. For example, the Comanche controlled a huge territory in sparsely populated central and northern Texas. Wanting to stabilize and develop that area — and as few people from central Mexico had chosen to resettle to this remote and hostile territory — the Mexican government encouraged Anglo-American immigration into present-day Texas, a region that bordered that United States. Mexico by law was a Catholic country; the Anglo-Americans were primarily Protestant English speakers from the southern United States. Some brought their black slaves, which after 1829 was contrary to Mexican law. In 1835, Santa Anna sought to centralize government rule in Mexico, suspending the 1824 constitution and promulgating the Seven Laws, which placed power in his hands. As a result, civil war spread across the country. Three new governments declared independence: the Republic of Texas, the Republic of the Rio Grande and the Republic of Yucatán. The largest blow to Mexico was the U.S. invasion of Mexico in 1846 in the Mexican–American War. Mexico lost much of its sparsely populated northern territory, sealed in the 1848 Treaty of Guadalupe Hidalgo. Despite that disastrous loss, Santa Anna returned to the presidency yet again before being ousted and exiled in the Liberal Revolution of Ayutla.