Although Columbus skirted the Costa Rican coast in 1502, resistance by the indigenous inhabitants and disease prevented the Spanish from establishing a permanent settlement until 1563, when Cartago was founded. The region was administered as part of the captaincy general of Guatemala. Few of the native inhabitants survived, and the colonists, unable to establish a hacienda system based on slave labor, generally became small landowners. From Cartago, westward expansion into the plateau began in the 18th cent.
Costa Rica became independent from Spain in 1821. From 1822 to 1823 it was part of the Mexican Empire of Augustín de Iturbide. It then became part of the Central American Federation until 1838, when the sovereign republic of Costa Rica was proclaimed. In 1857, Costa Rica participated in the defeat of the filibuster William Walker, who had taken over Nicaragua.
The cultivation of coffee, introduced in the 19th cent., led to the creation of a landed oligarchy that dominated the country until the administration of Tomás Guardia (1870–82). In 1874, Minor Cooper Keith founded Limón and introduced banana cultivation. Keith also started the United Fruit Company. Later many tracts had to be abandoned because of leaf blight. Costa Rica's history of orderly, democratic government began in the late 19th cent.
The orderly pattern was broken in 1917, when Federico Tinoco overthrew the elected president, Alfredo González. The majority of Costa Ricans, as well as the United States, opposed Tinoco, and he was deposed in 1919. Costa Rica cooperated with the United States during World War II and after the war joined the United Nations and other international organizations. Following the war, United Fruit started new plantations on the Pacific coast.
In 1948 there was a second breakdown of the political system. In a close presidential election Otilio Ulate appeared to have defeated a former president, Dr. Rafael Calderón. But the incumbent, Teodoro Picado, accused Ulate's supporters of fraud and obtained a congressional invalidation of the election. A six-week civil war ensued, at the conclusion of which a junta led by José Figueres Ferrer, a backer of Ulate, assumed power. Picado was exiled and the armed forces were disbanded, to be replaced by a civil guard. Forces from Nicaragua backed Picado, and the Organization of American States (OAS) was called upon to mediate between the two countries.
In 1949 a new constitution was adopted, and the junta transferred power to Ulate as the elected president. Figueres was elected his successor in 1953. In UN-supervised elections in 1958, Mario Enchadi Jiménez defeated Figueres's candidate. Politics remained stable in the 1960s. The Irazú volcano erupted in 1963–64 and caused serious damage to agriculture; another volcano, Arenal, erupted in 1968 for the first time in hundreds of years, killing many. Figueres was again elected president in 1970, and Daniel Oduber Quiros was elected president in 1974, but the ruling National Liberation Party (PLN) lost its majority in the legislature for the first time in 25 years. In the late 1970s the country entered a recession and found itself surrounded by increasingly unstable neighbors.
In the early 1980s the PLN returned to power. Oscar Arias Sánchez, the PLN candidate elected in 1986, worked to preserve his nation's neutrality. The economy continued to worsen, however, and in 1990 Rafael Angel Calderón Fournier of the Social Christian Unity party (PUSC) was elected to the presidency by a 3% margin. José María Figueres Olsen, the PLN candidate and son of José Figueres Ferrer, was elected president in 1994. In 1998, Miguel Ángel Rodríguez Echeverría of the PUSC won the presidency; he was succeeded by fellow party member Abel Pacheco de la Espriella in 2002.
The country was shaken in 2004 by charges that Presidents Calderón and Rodríguez had received illegal kickbacks from government contracts and that, after leaving office, President Figueres had received large consulting fees relating to government contracts. Calderón was convicted of embezzlement in 2009. Former president Oscar Arias Sánchez was elected to a second term in 2006. In Oct., 2007, Costa Ricans approved joining the Central American Free Trade Agreement (signed in 2004), but its accession was delayed until after legislation was enacted (Nov., 2008) that brought the nation into compliance with the accord.
In Feb., 2010, Arias Sánchez's vice president, Laura Chinchilla Miranda, was elected president. A center-leftist who is conservative on many social issues, Chinchilla was Costa Rica's first woman president. Tensions flared with Nicaragua in late 2010 over a disputed island at the San Juan River's mouth when Nicaraguan troops were sent there; the troops were not removed despite the Organization of American States' call for both sides to withdraw. Costa Rica subsequently brought the issue before the International Court of Justice; a 2011 interim ruling called on both sides to avoid the disputed area.
In the early 21st cent. Costa Rica has found itself increasing beset by Mexican drug gangs that have used the country as a transfer point between Colombia to the south and Mexico and the United States to the north. The resulting increase in crime has led to a closer relationship between Costa Rican security forces and U.S. law enforcement agencies and military.