Starting 1524 Spain conquers present-day Nicaragua as part of its Capitanate-General of Guatemala inside the Vice-Royalty of Mexico. Besides Nicaragua this includes also Costa Rica, El Salvador, Honduras and Guatemala. In 1821 the area becomes shortly independent as the Kingdom of Guatemala and in 1822 is incorporated into Mexico. In 1823 Nicaragua becomes a main part of the Central American Federation.

Nicaragua secedes from this federation in 1838 as the State of Nicaragua and is renamed Republic of Nicaragua in 1854. Nicragua is ruled through the 19th century by decendants of the Spanish colonists. Much of Nicaragua's politics since independence can be characterized by the rivalry between the liberal elite of Leon and the conservative elite of Granada, which often spills into civil war. Initially invited by the liberals in 1855 to join their struggle against the conservatives, an American named William Walker and his "filibusters" seize the presidency in 1856. The liberals and conservatives unite to drive him out of office in 1857, after which a period of three decades of conservative rule ensued.

Taking advantage of divisions within the conservative ranks, José Santos Zelaya López of the Partido Liberal (Liberal Party, PL) leads a liberal revolt that brought him to power in 1893. Zelaya ends the longstanding dispute with Britain over the Atlantic Coast in 1894 and reincorporates that region into Nicaragua. However, due to differences over an isthmian canal and concessions to Americans in Nicaragua as well as a concern for what was perceived as Nicaragua's destabilizing influence in the region, in 1909 the United States provides political support to conservative-led forces rebelling against Zelaya and intervene militarily to protect American lives and property. Zelaya resigns later that year.

After some interim presidents Adolfo Díaz Recines of the Partido Conservador (Conservative Party, PC) is president between 1911 and 1917. His conservative rule is followed by Emiliano Chamorro Vargas (1917-1921) and Diego Manuel Chamorro Bolaños (1921-1923). After his death there are some conservative interim presidents. In 1926 Adolfo Díaz Recines becomes president. With the exception of a 9-month period in 1925-26, the United States maintains troops in Nicaragua from 1912 until 1933. From 1927 until 1933 United States Marines stationed in Nicaragua engage in a running battle with rebel forces led by the liberal general Augusto Sandino, who rejects a 1927 negotiated agreement brokered by the United States to end the latest round of fighting between liberals and conservatives. In 1929 the PL takes over with José María Moncada Tapia (1929-1933) and Juan Bautista Sacasa Sacasa (1933-1936).

After the departure of United States troops, the commander of the National Guard Anastasio Somoza García out-maneuvers his political opponents. Sandino is assassinated in 1934 and in 1936 Somoza makes himself president and dictator. He makes the Partido Liberal Nacionalista (Liberal Nationalist Party, PLN) into his personal political vehicle. The Somoza family rules the country directly or indirectly until 1979. The last of this dynasty is Anastasio Somoza Debayle, who is president from 1967 until 1972 and from 1974 until 1979. That year the Frente Sandinista de Liberación Nacional (Sandinist National Liberation Front, FSLN) comes to power led by José Daniel Ortega Saavedra. In 1984 the sandinista government is confirmed in national elections. Ortega is chairman of the Junta of National Reconstruction until 1985. That year he becomes president. The sandinistas try to establish a communist state and anti-communists, supported by the United States, start an armed opposition. In response to both domestic and international pressure, the Sandinista regime enters into negotiations with the Nicaraguan resistance and agreed to nationwide elections in 1990. The civil war ends and Nicaragua becomes a democracy.

In these elections, which were proclaimed free and fair by international observers, Nicaraguan voters elected as their president the candidate of the Unión Nacional Opositora (National Opposition Union, UNO), Violeta Barrios Torres de Chamorro. During president Chamorro's nearly 7 years in office, her government achieves major progress toward consolidating democratic institutions, advancing national reconciliation, stabilizing the economy, privatizing state-owned enterprises, and reducing human rights violations. The 1996 elections are judged free and fair. This time Nicaraguans elect José Arnoldo Alemán Lacayo, leader of the conservative 'liberal' Partido Liberal Constitucionalista (Constitutional Liberal Party, PLC). This leads to the first transfer of power in recent Nicaraguan history from one democratically elected president. In 2001 Enrique Bolaños Geyer of the PLC is elected president. Also these elections are free and fair. Bolaños promises to reinvigorate the economy, create jobs, fight corruption and support the war against terrorism. Under his presidency Aleman is arrested for corruption.