Before the arrival European explorers to the Americas, El Salvador and Central-Mexico were once populated by Uto-Aztecan language speakers and both southern Mexico and El Salvador once belonged to the Mayan civilization. During Spanish colonization, both nations were part of the Viceroyalty of New Spain. In 1821, Mexico obtained independence from Spain and most nations of Central America, including El Salvador, belonged to the First Mexican Empire under Emperor Agustín de Iturbide. In 1823, the Mexican empire collapsed and El Salvador became part of the Federal Republic of Central America along with Guatemala, Honduras, Nicaragua and Costa Rica. In 1838, the union dissolved and El Salvador became its own independent states. That same year, El Salvador and Mexico established diplomatic relations. In 1917, both nations open diplomatic missions in each other's capitals, respectively and in 1943, their respective diplomatic missions were elevated to embassies. From 1979-1992, El Salvador was enveloped in a bloody civil war. During the war, several thousand Salvadorean citizens fled the country to Mexico where many stayed or continued onward to the United States. In 1992, the Salvadorean government and FMLN signed a peace agreement in Mexico City known as the Chapultepec Peace Accords thus in effect, ending the civil war. Both nations work together in combating drug trafficking and gang violence, including MS-13 of which are the main cause of havoc in El Salvador and their operations create insecurity in the country. In 2018, several hundreds to a few thousands Salvadorans formed part of the Central American migrant caravans and traversed all of Mexico to the northern city ofTijuana to request asylum in the United States. In January 2019, over 700 Salvadorans requested and obtained asylum in Mexico where many are choosing to remain rather than face the uncertainty of trying to request asylum in the US and also not wishing to be denied and deported back to El Salvador. In June 2019, Salvadoran President Nayib Bukele traveled to the Mexican state of Chiapas and met with Mexican PresidentAndrés Manuel López Obrador. Leaders of both nations discussed initiatives to decrease the flow of Salvadoran migrants to Mexico en route to the United States and Mexico's commitment to Central Americas development.
Both nations have signed several bilateral agreements such as Agreement on Regular and Permanent Change for Scientific, Literary or Artistic Works; Agreement for the Protection and Rehabilitation of Archaeological, Artistic and Historical Monuments; Agreement on Touristic Cooperation; Agreement of Cooperation to Combat Drug Trafficking and Drug Dependency; Treaty on the Execution of Criminal Sentences; Treaty for the Recovery and Return of Vehicles and Aircraft Stolen; Agreement on Scientific and Technical Cooperation; Extradition Treaty; Agreement on Educational and Cultural Cooperation; Treaty of Cooperation on Mutual Legal Assistance in Criminal Matters and an Air Transportation Agreement.
In June 2000, Mexico and El Salvador signed a free trade agreement which took effect in 2001. Since then, both Costa Rica and Nicaragua have joined the joint free trade agreement. In 2018, total trade between El Salvador and Mexico amounted to $965 million USD. El Salvador's main exports to Mexico include: harnesses for automobiles; cotton; synthetic fibers; covers, bags and bags; sports shirts; and cattle based products. Mexico's main exports to El Salvador include: flat screens; avocados; copper, aluminum and alloys; pulp and cellulose wadding; shampoos; cereal products; toilet paper; and lubricating oils. El Salvador is Mexico's sixth largest trading partner in Central America and 15th largest in Latin America, while Mexico is El Salvador fourth largest trading partner globally and third largest investor in the country. Several Mexican multinational companies such as América Móvil, Cemex, Grupo Bimbo and Gruma operate in El Salvador.