Nicaragua's indigenous people included the Nicaraos, Chorotegas and Lencas, who lived on the Pacific coast, and the Mískito, Sumo and Rama peoples, who lived on the Caribbean coast. In 1522, the Spanish conquistador Gil González Dávila tried to claim Nicaragua. The indigenous people resisted the Spanish invasion and drove González out. 

In 1524, Francisco Hernández de Córdoba defeated the indigenous people. For the next 300 years, Nicaragua was ruled by the Spanish. León was the capital city. The Mískito people, however, allied with Great Britain in the 17th century. British involvement in the Mískito Coast lasted into the 19th century.

In 1821, Nicaragua joined with Honduras, El Salvador, Costa Rica and Guatemala to declare independence from Spain. These countries formed the United Provinces of Central America. In 1838 Nicaragua declared its independence from this federation of provinces.

 The Americans became interested in Nicaragua because they needed a route from the Atlantic Ocean to the Pacific. Nicaraguan Liberals in León invited an American, William Walker, to help them in a civil war that broke out in 1854. In 1855, Walker captured Granada. He then declared himself president. When the Nicaraguans learned that Walker planned to conquer other Central American countries and annex the area to the United States as a slave territory, they overthrew him in 1857. 

  Did you know?
During the California gold rush, millionaire Cornelius Vanderbilt transported people by steamship from New York to Lake Nicaragua, then by stagecoach to the Pacific, and by steamship again to California.
From 1893 to 1909, José Santos Zelaya was president. Although he built roads, railways and ports and introduced public education, he was a harsh dictator who punished people who opposed him. When he resigned, civil war broke out. In 1912, the United States Marines intervened.

 The United States kept troops in Nicaragua from 1912 to 1933. A Nicaraguan peasant army, under General Augusto César Sandino, fought the Americans from 1926 to 1933. When the Americans withdrew in 1933, General Anastasio Somoza García became commander of the Nicaraguan National Guard. He arranged the assassination of Sandino in 1934 and became president in 1937. People who opposed his dictatorship were tortured or killed.

The Sandinista National Liberation Front (FSLN), named after Sandino, opposed Somoza's dictatorship. In a mass uprising in 1979, they overthrew the Somoza regime. The new government nationalized some private property and brought about a number of reforms. However, the United States supported the Contras, a group that waged war on the Sandinista government. 

The FSLN won the 1984 election, and Daniel Ortega Saavedra became president. The United States did not accept this result and continued to fund the Contra war. In 1990, the National Opposition Union, financed by the United States, was elected. The new government reversed many FSLN policies, and arrangements were made to demobilize the Contras. In 1997, Arnoldo Alemán Lacayo, a member of the conservative Liberal Alliance, became president.