The ruling by a California court halts the policy across the border in a setback to Trump’s anti-immigration policy.

A federal judge in the United States on Wednesday blocked the Trump administration from enforcing new asylum restrictions for immigrants at the US-Mexico border, marking the latest defeat for a president waging an all-out battle in the courts to stop the flow of migrants into the country.

The ruling by US District Judge Jon Tigar in San Francisco came hours after a judge in Washington decided to let the rules stand.

The California ruling halts the policy across the border as lawsuits play out in court.

The new asylum rules would prevent most migrants at the southern border from seeking asylum in the US if they passed through another country first.

Most of the immigrants crossing the border are from Central America, making most of them ineligible for asylum because they passed through Mexico.

It also would affect asylum seekers from Africa, Asia and South America who arrive regularly at the southern border.

The restrictions went into effect last week, though there were conflicting reports on whether US immigration agencies were actually enforcing it.

Top US officials say their plan would discourage migrants from leaving their countries, which they say is necessary to reduce the numbers of people that border agents are detaining.

Tigar, who was appointed by former President Barack Obama, has already barred less restrictive asylum policies from taking effect and could permanently block the new asylum policy.

The judge said the new policy could expose migrants to violence and abuse, deny their rights under international law and return them to countries they were fleeing.

He acknowledged that the country’s immigration system is overwhelmed by the surge in migrants from Central America over the last year.

“But shortcutting the law, or weakening the boundary between Congress and the Executive, are not the solutions to these problems,” Tigar said.

The Justice and Homeland Security Departments did not immediately respond to requests for comment.

President Donald Trump told reporters before his departure for a fundraiser in West Virginia that the Washington decision was a “tremendous ruling.” He added: “We appreciate it. We respect the courts very much. That helps us very much at the border.”

The policy has exceptions that would still allow a migrant to apply for US asylum: If someone has been trafficked, if an asylum seeker sought protection in a country but was denied or if the country the migrant passed through did not sign one of the major international treaties that govern how refugees are managed – though most Western countries have signed them.

Meanwhile, tens of thousands of people are waiting in Mexico on official and unofficial lists formed after US agents started turning away many asylum seekers, citing lack of space and delays in immigration courts.

Federal courts have prevented other Trump administration plans from taking effect, including a ban on asylum for anyone who crosses the southern border illegally.

A federal court also stopped the administration from detaining asylum seekers without giving them a chance to be released on bond.