Mexico has agreed to take "unprecedented steps" to help stem the flow of migrants to the US in order to avoid trade tariffs threatened by President Donald Trump.
Mr Trump revealed that a deal had been reached to suspend the tariffs "indefinitely" in a series of tweets.
He had threatened to implement import duties of 5%, rising every month, unless Mexico acted to curb migration.
The tariffs were due to come into effect on Monday.
The deal, also confirmed in a tweet by Mexico's Foreign Secretary Marcelo Ebrard, comes at the end of three days of negotiations, which saw Washington demand a crackdown on Central American migrants.
I am pleased to inform you that The United States of America has reached a signed agreement with Mexico. The Tariffs scheduled to be implemented by the U.S. on Monday, against Mexico, are hereby indefinitely suspended. Mexico, in turn, has agreed to take strong measures to....— Donald J. Trump (@realDonaldTrump) June 8, 2019
....stem the tide of Migration through Mexico, and to our Southern Border. This is being done to greatly reduce, or eliminate, Illegal Immigration coming from Mexico and into the United States. Details of the agreement will be released shortly by the State Department. Thank you!— Donald J. Trump (@realDonaldTrump) June 8, 2019
Mr Trump caught members of his own party unaware when he announced the proposed tariffs last week.
He had declared an emergency on the US-Mexico border in February, saying it was necessary in order to tackle what he claimed was a crisis with thousands of undocumented migrants crossing the frontier.
What do we know about the deal?
In a joint declaration released by the US state department, the two countries said Mexico would take "unprecedented" steps to curb irregular migration and human trafficking.
But it seems the US did not get one of its reported key demands that would have required Mexico to take in asylum seekers heading for the US and process their claims on its own soil.
Under the deal, Mexico agreed to:
- Deploy its National Guard throughout the country from Monday, pledging up to 6,000 additional troops along Mexico's southern border with Guatemala
- Take "decisive action" in tackling human smuggling networks
The US also agreed to:
- Expand its programme of sending asylum seekers back to Mexico while they awaited reviews of their claims. In return, the US would "work to accelerate" the adjudication process
Both countries pledged to "strengthen bilateral co-operation" over border security, including "co-ordinated actions" and information sharing.
The declaration added that discussions would continue, and final terms be accepted and announced within 90 days.
Should Mexico's actions "not have the expected results", the agreement warned that additional measures could be taken, but did not specify what these would be.
Mr Ebrard told journalists: "I think it was a fair balance, because they have more drastic measures and proposals at the start, and we have reached some middle point."
"We couldn't be more pleased with the agreement," US Treasury Secretary Steven Mnuchin told reporters at a separate news conference.
Mexico is currently one of the largest trading partners of the US, just behind China and Canada - two countries also locked in trade disputes with the US.
Trump tariff threat recedes - for now
By Will Grant, BBC Mexico and Central America correspondent
It's still unclear whether it was internal pressure within his party or the measures being offered by Mexico that dissuaded Mr Trump from implementing the plan. Or perhaps simply an appreciation of its potential consequences.
It became apparent during the talks just how intertwined the two neighbouring economies are, and many argued that a 5% tax on all Mexican goods would hurt US suppliers and customers too.
Furthermore, damaging the already fragile Mexican economy could have pushed it into a full recession and created more migrants heading north in search of work.
Still, some considered the bilateral meetings were useful, in part to recognise that both nations are facing a steep rise in undocumented immigration.
The plan to deploy military personnel to Mexico's southern border may well have helped bring this dispute to an end. However, President Trump has now tied immigration to bilateral trade and could easily do so again in the future should the situation fail to improve.
What is the reaction in Mexico?
President Andrés Manuel López Obrador ran for office vowing to stand up to the US and once said he would not allow Mexico to be Mr Trump's "whipping boy".
But some politicians felt he had given too much, too quickly, and they demanded to see details of the deal.
Ángel Ávila Romero, a senior member of the left-wing PRD party, said the agreement was "not a negotiation, it was a surrender".
"Mexico should not militarise its southern border. We are not the backyard of Donald Trump," he tweeted.
Marko Cortés, leader of the conservative National Action Party (PAN), said the sovereignty and dignity of Mexico had been damaged, newspaper El Universal reported.
At a rally on Saturday in the border city of Tijuana, Mr López Obrador hailed the new deal, but warned that it would not be enough for Mexico to tighten its borders alone.
The leftist leader said the US also needed to invest in the economic development of Central America to help combat "the lack of opportunity and poverty so that migration is optional".
What's the situation on the US-Mexico border?
On Wednesday, US Customs and Border Protection announced that migrant detentions had surged in May to the highest level in more than a decade.
Border Patrol apprehended 132,887 migrants attempting to enter the US from Mexico in May - a 33% increase from the month before.
The arrests were the highest monthly total since Mr Trump took office.
"We are in a full-blown emergency, and I cannot say this stronger, the system is broken," said acting CBP Commissioner John Sanders.
Official figures show illegal border crossings have been in decline since 2000.
In 2000, 1.6 million people were apprehended trying to cross the border illegally - that number was just under 400,000 in 2018.
In 2017, Mr Trump's first year in office, the figures were the lowest they had been since 1971.
In the past two years, however, the number of arrests has been rising again, especially in recent months.