The order had been requested by two US civil rights groups, which launch legal action after the president announced restrictions intended to stop caravans of Central Americans from entering the country.
His ban, proposed to remain in place for three months, would potentially make it harder for thousands of people who enter the US to avoid deportation.
It was blocked by district judge Jon Tigar, who issued a temporary restraining order at a court in San Fransciso after hearing objections from the American Civil Liberties Union (ACLU) and the Centre for Constitutional Rights (CCR).
“Individuals are entitled to asylum if they cross between ports of entry,” said Baher Azmy, a lawyer for the CCR. “It couldn’t be clearer.”
The Department of Homeland Security (DHS) says about 70,000 people a year apply for asylum after surrendering to immigration agents, often in the Arizona desert or on the north bank of the Rio Grande river in Texas.
The government has said asylum-seekers at the southern border must present themselves at official border crossing. But many crossings already have lengthy waiting times, with migrants often forced to linger in shelters or outdoor camps in Mexico for weeks.
Around 3,000 Central American migrants in the first of the caravans arrived last week in Tijuana, Mexico, across the border from San Diego, California. US authorities said they expected another 7,000 to follow.
Many are refugees who have travelled for weeks to reach the US-Mexico frontier after fleeing violence and poverty in Honduras, El Salvador and Guatemala.
US border inspectors at the main crossing in San Diego only process about 100 asylum claims a day, meaning some of the migrants face waiting months in Tijuana if they apply at official crossings.
About 6,000 US troops have been deployed to the border, where the American government has erected concrete barriers and razor-wire fences to keep people out.
Mr Trump has depicted the caravans as a threat to national security and attempted to capitalise on fear of immigration during the run-up to the midterm elections.
The president’s asylum restrictions invoked the same emergency powers used early last year in his travel ban, which mostly targeted Muslims.
According to DHS, which oversees customs and border protections, 107 people had been detained after seeking asylum away from official crossings since the order took effect on 9 November.
ACLU lawyer Lee Gelernt said that some people seeking asylum cross between official ports because “they’re in real danger,” either in their countries of origin or in Mexico.
“We don’t condone people entering between ports of entry, but Congress has made the decision that if they do, they still need to be allowed to apply for asylum,” he said.
The civil rights groups argued the new restrictions violated administrative and immigration law.
In his ruling, Mr Tigar said Congress had clearly mandated that immigrants can apply for asylum regardless of how they entered the country. He called the latest rules an “extreme departure” from prior practice.
“Whatever the scope of the president’s authority, he may not rewrite the immigration laws to impose a condition that Congress has expressly forbidden,” wrote the judge, who was nominated to the court by Barack Obama.
The restraining order takes effect immediately and applies nationwide until 19 December, when the judge scheduled a hearing to consider a more long-lasting injunction.
Previous Trump immigration policies, including measures targeting sanctuary cities, have also been blocked by the courts.