In 1821, Mexico won its independence from Spain. The new Mexican government was not particularly stable and was faced with a number of internal challenges. In 1830, the Mexican government passed a law that prohibited further immigration from the United States. This law was intended to prevent the further influx of American settlers into Texas, who had been increasingly moving into the region in the years since Mexico's independence.
Despite the law, American settlers continued to move into Texas and soon outnumbered the Mexican population. The American settlers were not subject to Mexican laws and began to demand more political rights. In 1835, the American settlers in Texas revolted against the Mexican government and declared independence. The Republic of Texas was formed, and the Mexican government refused to recognize it.
In 1845, the United States annexed Texas, which led to the Mexican-American War. The war lasted from 1846 to 1848 and resulted in the defeat of Mexico. As a result of the war, Mexico lost half of its territory, including the present-day states of California, Nevada, Utah, New Mexico, and parts of Arizona, Colorado, and Wyoming. The war also resulted in the death of thousands of Mexican soldiers and civilians.