Many of those arriving are fleeing violence or poverty and travel north through Mexico until they reach the US border. Upon arrival, they must pass a "credible fear" interview to seek asylum in the US, which most do.

The rule change means they would fail had they not claimed asylum in another country they had first passed through.

"Once again the Executive Branch has issued a rule that seeks to upend longstanding practices regarding refugees who seek shelter from persecution," Justice Sotomayor wrote.

Image copyrightReutersImage caption
Migrants at the border last month in Matamoros, Tamaulipas, Mexico

The route to the US is fraught with risks, with Central American migrants often deliberately sought out by gangs in neighbouring countries because they are vulnerable.

There are questions over whether Mexico and Guatemala can cope with a surge in asylum claimants.

It's also unclear if other countries will co-operate with what amounts to a unilateral US policy.

Mexican officials, who have been working to crack down on migration, have already pushed back strongly against the plan.

Responding to the Supreme Court ruling on Thursday, Foreign Minister Marcelo Ebrard reiterated that Mexico would not become a "third country" for US-bound asylum seekers.

"It's a US issue and obviously we don't agree with it, we have a different policy," he told reporters.

Earlier this week, Mark Morgan, acting commissioner of US Customs and Border Protection, said that in August 64,000 people were detained or turned back at the south-west border - down 22% from July and 56% from May.

Mr Ebrard added that he expected the number of migrants passing through Mexico to fall further.

Central American countries, with the exception of Guatemala, have also declined to sign "safe third country" agreements that would mean the US could send back asylum seekers who passed through without seeking protection.

The Guatemalan deal, signed by its outgoing president, has faced legal hurdles and is yet to come into force.

On Wednesday, Mexican President Andres Manuel Lopez Obrador posted an image of himself on the phone to President Trump, who said they had had "an excellent telephone conversation".

The Supreme Court ruling is the second in favour of Mr Trump's migration plans so far this year. In July the nation's top court ruled Mr Trump could use $2.5bn (£2bn) of Pentagon funds for his long-promised southern border wall.