At the time when the Spaniards arrived in 1524, El Salvador had already been inhabited by the Pipil Amerindians, who were related to the Nahuatl tribes of the Aztecs who came from Mexico a few thousand years earlier. Other communities such as the Lenca tribe from present-day Honduras were also living there.
The Spaniards were repelled in 1524, but returned the following year and defeated the indigenous people, founded San Salvador and put El Salvador under the administrative rule of the captaincy general of Guatemala. The colonists established a farming community and some ranches. This was followed by immigration from Europe which brought along the Roman Catholic Church.
The Napoleonic Wars and the French Revolution before it gave rise to calls for independence in Spanish South America. In 1811, Jose Matias Delgado, a priest from the Church of La Merced, led the call for independence, but faced resistance by royalists and subsequently by resistance of Guatemala (which had overall administrative control of El Salvador) which wanted to join Mexico. In 1823 El Salvador joined the Central America Federation (made up of Guatemala, El Salvador, Honduras, Nicaragua and Costa Rica), went its own way in 1839 and eventually proclaimed a republic in January 1859.
The rest of the 19th century in El Salvador was characterized by great political instability with frequent changes of government, and the economy dominated by a dozen large plantation owners and many in the indigenous population displaced from their land, thereby creating a big gap between the landowners and the landless. The instability eventually brought the military into power in 1931 which lasted for nearly fifty years but which was not able to solve the social inequalities. As a result, there was mass migration of Salvadorans to neighbouring Honduras in the 1960s, which led to a war between the two countries 1969. It took more than 10 years for the countries to reach a peace settlement and another 10 years to settle a border dispute with the help of the Organisation of American States and the International Court of Justice.
Meanwhile, the country continued to be beset by political instability, human right issues, guerilla or armed movements from the left and the right and bouts of reforms in between, but democracy failed to take hold. Civil war ensued from 1980-1992 and more than 75,000 people were killed. Finally in 1992, a peace accord was reached between the contestants and former guerillas were allowed to participate in elections.