Spain's control over its colonies in the New World was threatened in the early 1800s by the struggle for national independence throughout the entire region. Weakened by the French invasion in 1794 and internal upheaval, Spain tried to hold onto its richest colonies, which led to even further neglect of its poorer Central American territories. Resentment toward the Spanish-born elite (peninsulares--those born in Spain and the only persons allowed to administer Spanish colonies) grew among Nicaraguan creoles. The first local movements against Spanish rule in Central America occurred in 1811, when the Province of El Salvador staged a revolt. Peninsular authorities were deposed and replaced by creoles, who demanded less repressive laws. Although the Province of Nicaragua officially refused to join the rebellion, a popular uprising soon broke out. Violence and political rivalry prevailed in all of the Central American colonies during the ensuing decade.
Establishment of an independent Nicaragua came in stages. The first stage occurred in 1821 when the Captaincy General of Guatemala formally declared its independence from Spain on September 15, which is still celebrated as independence day. At first the captaincy general was part of the Mexican Empire under General Agustín de Iturbide, but efforts by Mexico to control the region were resisted all over Central America. Separatist feelings throughout the isthmus grew, however, and five of the United Provinces of Central America--Costa Rica, El Salvador, Guatemala, Honduras, andd Nicaragua--declared their independence from Mexico in July 1823. The sixth province, Chiapas, opted to remain with Mexico. Under a weak federal government, each province created its own independent internal administration. Inadequate communication and internal conflicts, however, overshadowed efforts to institutionalize the federation for the next decade and a half. Efforts to centralize power led to civil war between 1826 and 1829. The federation finally dissolved in 1837, and a Constituent Assembly formally declared Nicaragua's independence from the United Provinces of Central America on April 30, 1838.