Before the arrival of the Spaniards, El Salvador was inhabited by the Pipils, descendants of the Aztecs and the Toltecs of Mexico, who had arrived in the 12th cent. In 1524 Pedro de Alvarado landed and began a series of campaigns that resulted in Spanish control. With independence from Spain in 1821, it became briefly a part of the Mexican Empire of Augustín de Iturbide, and after the empire collapsed (1823) El Salvador joined the Central American Federation. El Salvador protested the dominance of Guatemala and under Francisco Morazán succeeded in having the federal capital transferred (1831) to San Salvador. After the dissolution of the federation (1839), the republic was plagued by frequent interference from the dictators of neighboring countries, notably Rafael Carrera and Justo Rufino Barrios of Guatemala and José Santos Zelaya of Nicaragua.
The primacy of coffee cultivation in the economy began in the second half of the 19th cent. Intense cultivation led to the predominance of landed proprietors, and the economy became vulnerable to fluctuations in the world market price for coffee. In 1931, Maximiliano Hernández Martínez, capitalizing on discontent caused by the collapse of coffee prices, led a coup. His dictatorship lasted until 1944, after which there was chronic political unrest.
Under the authoritarian rule of Major Oscar Osorio (1950–56) and Lt. Col. José María Lemus (1956–60) considerable economic progress was made. Lemus was overthrown by a coup, and after a confused period a junta composed of leaders of the National Conciliation party came to power in June, 1961. The junta's candidate, Lt. Col. Julio Adalberto Rivera, was elected president in 1962. He was succeeded in 1967 by Col. Fidel Sánchez Hernández.
Relations with Honduras deteriorated in the late 1960s. There was a border clash in 1967, and a four-day war broke out in July, 1969. The Salvadoran forces that had invaded Honduras were withdrawn, but not until 1992 was an agreement that largely settled the border controversy with Honduras signed. The last disputed border area was finally marked in 2006.
In the 1970s El Salvador's overpopulation, economic problems, and inequitable social system led to social and political unrest; by the end of the decade, murder and other terrorism by leftist guerrillas and especially by right-wing "death squads" had become common. In 1979, Gen. Carlos Humberto Romero, the last in a series of presidents whose elections were denounced by many as fraudulent, was overthrown by a military junta. Murders and other terrorism continued, and the unrest erupted into a full-scale civil war between the government and guerrillas of the leading opposition group, the FMLN.
In 1990, José Napoleón Duarte, a Christian Democrat, assumed the presidency under the junta and called for presidential elections, which he won in 1984. Despite his reputation as a reformer, he did not appear able to rein in the army and control the death squads. These excesses continued after the election in 1989 of President Alfredo Cristiani, leader of the right-wing ARENA party.
In 1991, however, the Cristiani government, with help from the United Nations, negotiated with the FMLN, and in Jan., 1992, a peace treaty with the rebels was signed, ending the bloody 12-year civil war that killed over 70,000 people. The FMLN demobilized and participated in the postwar 1994 elections, which resulted in the presidency of Armando Calderón Sol, the ARENA candidate. The army was apparently reined in, and terrorism and violence, by both left and right, virtually disappeared. A major program was put in place to transfer land (80% of which was concentrated in the hands of the wealthy) to former combatants. However, progress in implementing reforms and rebuilding the economy was slow, and was further hindered by a major hurricane in 1998.
The ARENA party remained in power with the election of Francisco Guillermo Flores Pérez to the presidency in 1999. In Mar., 2000, however, the FMLN won the greatest number of seats in the National Assembly, although not enough to control the legislature. Two earthquakes struck central El Salvador a month apart early in 2001, killing about a thousand people and leaving many homeless. In Mar., 2003, the FMLN again won the largest bloc of assembly seats, but failed to win a majority. The presidential elections a year later resulted in an ARENA victory; Elías Antonio "Tony"Saca received 57% of the vote. An earthquake in Jan., 2005, killed nearly 700 people. An increase in gang-related violence in 2005 led to army patrols on the country's streets.
Legislative elections in Mar., 2006, gave a plurality of the seats to ARENA, but it failed to win a majority and the FMLN was a close second. The government mounted a crackdown against criminal gangs in Aug., 2006; in October it said it had uncovered an assassination plot against the president that was said to be linked to the anti-gang campaign. Crime and deteriorating economic conditions contributed to the election of Mauricio Funes, a journalist and moderate leftist who was the FMLN candidate, as president in Mar., 2009; the FMLN also won a plurality of seats in the National Assembly in January. Funes became the first leftist candidate to be elected to the office. The assembly elections in Mar., 2012, resulted in losses for the FMLN, and ARENA edged ahead to become the largest party in the legislature; no party won a majority.