Like the rest of Central America, Costa Rica never fought for independence from Spain. On September 15, 1821, after the final Spanish defeat in the Mexican War of Independence (1810–21), the authorities in Guatemala declared the independence of all of Central America. That date is still celebrated as Independence Day in Costa Rica even though, technically, under the Spanish Constitution of 1812 that had been readopted in 1820, Nicaragua and Costa Rica had become an autonomous province with its capital in León.
Upon independence, Costa Rican authorities faced the issue of officially deciding the future of the country. Two bands formed, the Imperialists, defended by Cartago and Heredia cities which were in favor of joining the Mexican Empire, and the Republicans, represented by the cities of San José and Alajuela who defended full independence. Because of the lack of agreement on these two possible outcomes, the first civil war of Costa Rica occurred. The Battle of Ochomogo, which took place on the Hill of Ochomogo, located in the Central Valley in 1823. The conflict was won by the Republicans and, as a consequence, the city of Cartago lost its status as the capital, which moved to San José.