
Early U.S.–Mexico relations grew out of the earlier relations between the fledgling nation of the United States and the Spanish Empire began with the birth of the new American nation. Modern-day Mexico formed the core area of the Viceroyalty of New Spain when the United States gained independence from Great Britain in the Revolutionary War. Spain had served as an ally to the American colonists in that war. But while relations initially began cordially enough, they would become strained over developments in Texas. In the early 19th century the United States claimed that Texas was part of the territory of Louisiana, and therefore had been rightfully acquired by the United States as part of the Louisiana Purchase from France in 1803. The Spanish disputed this and the western boundaries of Louisiana were never clearly defined. In 1819 the dispute was resolved with the signing of the Adams–Onís Treaty, in which the United States relinquished its claims to Texas and instead purchased Spanish Florida.
In 1821 New Spain gained its independence from Spain and established the First Mexican Empire under the rule of Agustín de Iturbide. Independent Mexico was soon recognized by the United States and the two countries quickly established diplomatic relations, with Joel Poinsett serving as the first envoy. In 1828 Mexico and the United States confirmed the boundaries established by the Adams–Onís Treaty by concluding the Treaty of Limits, but not all Americans were happy with the treaty, especially because it relinquished America's claim to Texas. Poinsett was sent by President James Monroe to negotiate the acquisition of new territories for the United States, including Texas, New Mexico, and as parts of California. Poinsett's offer to purchase these areas was rejected by the Mexican Ministry of Foreign Affairs. Poinsett was successful in obtaining preferential treatment of U.S. goods over those of Britain.
Texas remained a focal point of U.S-Mexico relations for decades. Slavery had expanded into Texas, even though it had been abolished in Mexico. Beginning in the 1820s, Americans led by Stephan F. Austin and other non-Mexicans began to settle in eastern Texas in large numbers. These Anglo-American settlers, known as Texians, wanted autonomy from the central Mexican government and the expansion of slavery into Mexico. Slavery had been abolished in 1829 under Mexican president Vicente Guerrero. This conflict led to the Texas Revolution, which came on the heels of 1835 amendments to the Constitution of Mexico, which called for more direct intervention in Texas by the Mexican government. Public opinion in the southern United States was sympathetic to the Texians. Following the war a Republic of Texas was declared, though independence was not recognized by Mexico. The boundaries between the two nations were never agreed upon. In 1845 the United States annexed Texas, leading to a major border dispute and eventually to the Mexican–American War.
The Mexican–American War was fought from 1846 to 1848. Mexico refused to acknowledge that Texas had achieved independence and warned that annexation to the United States would mean war. The United States annexed Texas in late 1845. The war began the next spring. President James K. Polk encouraged Congress to declare war following a number of skirmishes on the disputed Mexican–American border. The war did not work out well for Mexico. The Americans seized New Mexico and California and invaded Mexico's northern provinces. In September 1847, U.S. troops under General Winfield Scott captured Mexico City. The war ended in a decisive U.S. victory. The Treaty of Guadalupe Hidalgo was signed and Mexico was forced to sell California and New Mexico, to the United States in the Mexican Cession. Additionally, Mexico relinquished its claims to Texas, and the United States forgave Mexico's debts to U.S. citizens. Mexicans in the annexed areas became full U.S. citizens.
In 1854 the United States purchased an additional 30,000 square miles of desert land from Mexico in the Gadsden Purchase for $10 million. The goal was to build a rail line through southern Arizona to California. The sale by Mexican President Antonio López de Santa Anna was followed by the Revolution of Ayutla in Mexico in which Santa Ana was overthrown as President. Eventually the liberal government of Benito Juárez negotiated with the U.S. A treaty was concluded in 1859 between Melchor Ocampo and the U.S. representative Robert Milligan McLane, giving their names to the McLane-Ocampo Treaty. The U.S. Senate failed to ratify the treaty. Had it passed, Mexico would have made significant concessions to the U.S. in exchange for cash desperately needed by the liberal Mexican government.
In 1861, Mexican conservatives looked to French leader Napoleon III to abolish the Republic led by liberal President Benito Juárez. France favored the Confederate States of America in the Civil War, but did not go so far as diplomatic recognition of the Confederacy. The French expected that a Confederate victory would lead to French economic dominance in Mexico. France invaded Mexico and installed an Austrian prince Maximilian I of Mexico as its ruler in 1864. Juárez was able to obtain support in the U.S. Congress and the U.S. protested France's violation of the Monroe Doctrine. Once the American Civil War came to a close in April 1865, the U.S. allowed supporters of Juárez to openly purchase weapons and ammunition. Napoleon III ultimately withdrew his army and Emperor Maximilian was executed by the Mexican government in 1867. The US support given to Juarez helped improve the U.S.–Mexican relationship.
General Porfirio Díaz's seized the presidency of Mexico in 1876. His givernment was more welcoming to foreign investment in order to reap economic gain. Díaz was a military hero who had fought ably against the French. Díaz had ousted president Sebastián Lerdo de Tejada in the Revolution of Tuxtepec. The U.S. did not recognize the Díaz government until 1878, when Rutherford B. Hayes was president. One issue causing tension between Mexico and the U.S. were indigenous groups whose traditional territories straddled what was now an international boundary, most notably the Apache. The Apache leader Geronimo conducted raids on both sides of the border. Bandits operating in both countries also frequently crossed the border to raid Mexican and American settlements, taking advantage of mutual distrust between the two nations. These common enemies helped bring about US recognition of the Díaz regime. U.S. investors and their supporters in Congress also had a common interest with Mexico, the building of a railway line between Mexico City and El Paso, Texas. With the construction of the railway line linking Mexico and the United States, the border region developed into a vibrant economic zone. The construction of the railway and collaboration of the United States and Mexican armies ended the Apache Wars in the late 1880s.
In 1909, William Howard Taft and Porfirio Díaz planned a summit in El Paso, Texas, and Ciudad Juárez, Mexico, the first meeting between a U.S. and a Mexican president, and the first time a sitting American president would cross the border into Mexico. Taft agreed to support Diaz in order to protect the several billion dollars of American capital then invested in Mexico. The Texas Rangers, 4,000 U.S. and Mexican troops, U.S. Secret Service agents, Bureau of Investigation agents (later FBI) and U.S. marshals were all called in to provide security. An additional 250 private security detail led by Frederick Russell Burnham was hired by John Hays Hammond, a close friend of Taft from Yale. Burnham, along with his business partners, held considerable mining interests in Mexico. On October 16, 1909, the day of the summit, Burnham and Private C.R. Moore, a Texas Ranger, discovered a man holding a concealed palm pistol standing at the El Paso Chamber of Commerce building along the procession route. Burnham and Moore captured and disarmed would-be the assassin within only a few feet of Taft and Díaz.

In 1913. shortly after the assassination of President Francisco I. Madero, Woodrow Wilson rejected the legitimacy of Madero's successor, President Huerta, whose administration Wilson called a "government of butchers". He demanded in Mexico hold democratic elections. After U.S. navy personnel were arrested in the port of Tampico by Huerta's soldiers, the U.S. seized Veracruz, resulting in the death of 170 Mexican soldiers and an unknown number of Mexican civilians. In 1916 Wilson sent an unsuccessful punitive expedition, led by General John J. Pershing, to capture Villa after he murdered Americans in his raid on Columbus, New Mexico.
At the same time, Germany was trying to divert American attention from Europe by sparking a war. It sent Mexico the Zimmermann Telegram in January 1917, offering a military alliance to fight the U.S. The British intercepted the message and Wilson released it to the press, escalating demands for American entry into the European War. The Mexican government rejected the proposal and stayed neutral in the conflict, other than selling oil to Great Britain.
In 1924 General Plutarco Elías Calles became the new President of Mexico. He implemented articles of the Mexican Constitution of 1917 that gave the state the power to suppress the role of the Roman Catholic Church in Mexico. A major civil uprising broke out, known as the Cristero War. U.S. Ambassador Dwight W. Morrow played a key role in brokering an agreement between the Roman Catholic hierarchy and the Mexican government which ended the conflict in 1929.
The presidency of revolutionary general Lázaro Cárdenas del Río caused concern about the risk to Standard Oil's major investments in Mexico. On March 18, 1938, President Cárdenas used constitutional powers to expropriate foreign oil interests in Mexico and created the government-owned Petroleos Mexicanos or PEMEX. President Franklin D. Roosevelt was implementing the Good Neighbor Policy, and did not intervene on Standard Oil's behalf. He wanted friendly relations with Mexico, anticipating the coming conflict in Europe. However, in light of the Great Depression, the United States implemented a program of expelling Mexicans from the U.S. in what was known as Mexican Repatriation in order to create more jobs for Americans. When the U.S. did enter World War II, it negotiated an agreement with Mexican President Manuel Avila Camacho to be allies in the conflict against the Axis powers. The U.S. bought Mexican metals, especially copper and silver, and implemented a labor agreement with Mexico, known as the Bracero Program. Mexican agricultural workers were brought under contract to the U.S. to do mainly agricultural labor as well as harvesting timber in the northwest. The program continued in effect until 1964 when organized labor in the U.S. pushed for ending it. An arrangement was also made for 250,000 Mexican citizens living in the United States served in the American forces. Over 1000 were killed in combat.
The alliance between the two nations during World War II made for better relations between them. Mexican President Manuel Avila Camacho met with both Franklin D. Roosevelt and later with Harry S. Truman. Camacho was pro-business and pro-religious Camacho visited Truman near the centenary of the Mexican–American War and Truman returned some of the Mexican banners captured by the United States in that war. When World War ended, the need decreased for Mexican labor via the guest-worker Bracero Program or for Mexican raw materials to fight a war. Mexico supported U.S. policies in the Cold War and did not challenge U.S. intervention in Guatemala that removed leftist president Jacobo Arbenz.
Mexico, United States and Canada signed the North American Free Trade Agreement (NAFTA) in 1994 with the goal of eliminating barriers to trade and investment. Since then, the United States and Mexico have strengthened their economic ties. The US is Mexico's largest trading partner, accounting for close to half of all exports in 2008 and more than half of all imports in 2009. For the US, Mexico is the third largest trading partner after Canada and China as of June 2010. In 2017, two-way trade between both nations amounted to $521.5 billion USD. Foreign direct investment (FDI) into Mexico has risen dramatically since NAFTA went into effect and in 2008. 41% of all FDI came from U.S. sources. Roughly half of this investment goes to manufacturing. Wal-Mart, is the largest private sector employer in Mexico.
One of the most contentious issues between the two nations is illegal immigration. As of 2009, 62% of illegal immigrants in the United States come from Mexico. This number was reduced to 52% by 2014. Those who enter the United States illegally are smuggled in by individuals known as "coyotes". According to the World Bank, Mexico received US$18.1 billion from individuals in the United States in 2005. The number of illegal immigrants was at its highest in 2007, at 12.2 million, and has since dropped to 11.1 million in 2014. The prevalence of illegal aliens and drug smugglers has resulted in increased border security. Mexico is a major source of drugs entering the United States. By the 1990s, it was reported that 80%–90% of the cocaine smuggled into the United States arrived through Mexico.
Since 2000, the Mexican government has increased its efforts to combat the drug cartels. The United States sent aid to Mexico for this purpose through the Merida Initiative. As of November 2009, the U.S. has delivered about $214 million of the pledged $1.6 billion.
On August 24, 2012, a United States embassy vehicle was fired upon by Mexican Federal Police agents, causing two occupants of the vehicle to be wounded. The incident occurred south of Mexico City, while the vehicle had two Americans and a Mexican Navy captain who were traveling to a Mexican naval installation. Twelve Mexican Federal Police agents were arrested for the shooting. The two Americans were later reported to be CIA agents, who were investigating a kidnapping. The two CIA agents were victims of a targeted assassination attempt, and the Mexican Federal Police agents were working for the Beltran Leyva Cartel.
Conversely, the US is the largest source of illicit traffic of weapons to Mexico. Many of the traceable weapons come from American weapons markets and festivals that do not have regulations for the buyers. Firearms that make their way to Mexico come from the American civilian market. Grenades are also smuggled from the US to Mexico. In 2008, it was reported that 90% of arms captured in Mexico come from the United States. In 2015, Official reports of the U.S. government and the Bureau of Alcohol, Tobacco, Firearms and explosives (ATF) revealed that in recent years, Mexican cartels improved their firearm power, and that 70% of their weapons come from the U.S. The ATF's Project Gunrunner has the goal of stopping the selling and exportation of guns from the United States into Mexico. However, in February 2011, it was revealed that the ATF was permitting so-called "straw purchase" firearm sales to traffickers, and allowing the guns to be transported to Mexico. Several of the guns sold under the Project Gunrunner were recovered from crime scenes in Arizona, and at crime scenes throughout Mexico. In "Operation Black Swan" Joaquín Guzmán Loera was captured, and it was confirmed that one of the weapons seized from Guzman's gunmen was one of the many weapons that were "lost" during the Project Gunrunner. A cache of weapons from Project Gunrunner were also found in a secret compartment from the "safe house" of José Antonio Marrufo "El Jaguar, a criminal accused of many killings in Ciudad Juarez.
During the 2016 U.S. presidential election, candidate Donald Trump made a central campaign promise of building a border wall with Mexico and renegotiating the NAFTA trade agreement. Trump characterized illegal immigrants as criminals. On July 6, 2015, he famously said:
"The Mexican Government is forcing their most unwanted people into the United States. They are, in many cases, criminals, drug dealers, rapists, etc. This was evident just this week when, as an example, a young woman in San Francisco was viciously killed by a 5-time deported Mexican with a long criminal record, who was forced back into the United States because they didn't want him in Mexico. This is merely one of thousands of similar incidents throughout the United States. In other words, the worst elements in Mexico are being pushed into the United States by the Mexican government. The largest suppliers of heroin, cocaine and other illicit drugs are Mexican cartels that arrange to have Mexican immigrants trying to cross the borders and smuggle in the drugs. The Border Patrol knows this. Likewise, tremendous infectious disease is pouring across the border. The United States has become a dumping ground for Mexico and, in fact, for many other parts of the world. On the other hand, many fabulous people come in from Mexico and our country is better for it. But these people are here legally, and are severely hurt by those coming in illegally. I am proud to say that I know many hard working Mexicans—many of them are working for and with me and, just like our country, my organization is better for it."
Prior to taking office, Trump promised to deport the 11 million illegal immigrants living in the United States and to build a wall along the Mexico–United States border. In January 2017, Trump signed an executive order directing the DHS Secretary to begin work on a wall. Following the announcement, Mexican President Enrique Peña Nieto cancelled a scheduled visit to the United States. Trump said that Mexico would pay for the construction of the wall, but did not explain how the U.S. government would compel Mexico to do so. Mexico has refused to provide any funding for the movie. Peña Nieto listed ten goals he would seek in NAFTA negotiations, notably safeguarding the free flow of remittances, which amount to about $25 billion per year.
In February 2017 the Mexican government stated they would not accept foreign nationals from third countries that the United States wants to deport. In recent years, the majority of illegal aliens crossing from Mexico into the United States have been from Central America.
As of August 2017, prototypes for the wall had been completed, but U.S. Congress had only approved $341 million to maintain the existing structures along the border, without approving the requested budget for a new wall. In August 2018 Mexico and the United States reached a bilateral agreement on a revamped NAFTA trade deal, including provisions to boost automobile production in the U.S.
By February 2018, arrests of undocumented immigrants increased by 40% during the Trump presidency. Arrests of noncriminal undocumented immigrants were twice as high as they were during President Obama's final year in office. In March 2018, the Commerce Department announced that it would add a citizenship question to the 2020 census. The inclusion of such a question will likely result in severe reduction in the population of states such as California, where undocumented immigrants will be less likely to respond to the census. California's attorney general announced his attention to sue the administration over the decision. Similar suits have been filed in New York, Washington D.C., and several cities.
President Trump drew criticism for new guidelines implemented in April 2018 through an executive order in which federal authorities separated children from their parents, relatives, or other adults who accompanied them in their illegal border crossing. The policy involved prosecuting all adults who were detained at the U.S.–Mexico border, sending the parents to federal jails, and placing children and infants under the supervision of the U.S. Department of Health and Human Services. The policy led to the separation of almost 3,000 children from their parents.

During the 2018 mid-term election campaign, President Trump sent nearly 4,000 troops to the U.S.-Mexico border to protect the United States against an anticipated caravan of Central American migrants.
Many have criticized President Trump for the ferocity of his efforts to prevent illegal immigration, while others see illegal immigration from Mexico as a viable threat both to the economy and to national security.