A federal judge on Wednesday ordered the Trump administration to continue accepting asylum claims from all eligible migrants arriving in the United States, temporarily thwarting the president’s latest attempt to stanch the flow of migrants crossing the southern border.

Judge Jon S. Tigar of US District Court in San Francisco issued a preliminary injunction against a new rule that would have effectively banned asylum claims in the United States for most Central American migrants, who have been arriving in record numbers this year. It would have also affected many migrants from Africa, Asia and other regions.

The decision came on the same day that a federal judge in Washington, hearing a separate challenge, let the new rule stand, briefly delivering the administration a win.

But Tigar’s order prevents the rule from being carried out until the legal issues can be debated more fully.

The rule, which has been applied on a limited basis in Texas, requires migrants to apply for and be denied asylum in the first safe country they arrive in on their way to the United States – in many of the current cases, Mexico – before applying for protections here.

‘Families belong together’ protests over Trump immigration policy Show all 8 1 /8 ‘Families belong together’ protests over Trump immigration policy ‘Families belong together’ protests over Trump immigration policy Mishawaka, Indiana AP ‘Families belong together’ protests over Trump immigration policy Washington DC AFP/Getty Images ‘Families belong together’ protests over Trump immigration policy New York Mayor Bill De Blasio speaks in Tornillo, Texas alongside the many other US mayors who have called for detained immigrant children to be reunited with their families AP ‘Families belong together’ protests over Trump immigration policy Albuquerque Mayor Tim Kelle leaves a teddy bear as a gift for detained immigrant children in Tornillo, Texas AP ‘Families belong together’ protests over Trump immigration policy Seattle Mayor Jenny Durkan and Los Angeles Mayor Eric Garcetti leave sandals as gifts for detained immigrant children in Tornillo, Texas AP ‘Families belong together’ protests over Trump immigration policy San Diego, California EPA ‘Families belong together’ protests over Trump immigration policy US embassy, Mexico City AFP/Getty Images ‘Families belong together’ protests over Trump immigration policy San Diego, California EPA

Because migrants from Honduras, El Salvador and Guatemala make up a vast majority of asylum-seekers arriving at the southern border, the policy would virtually terminate asylum there.

“This new rule is likely invalid because it is inconsistent with the existing asylum laws,” Tigar wrote in his ruling Wednesday, adding that the government’s decision to put it in place was “arbitrary and capricious.”

The government, which is expected to appeal the decision, has said that the rule intends to prevent exploitation of the asylum system by those who unlawfully immigrate to the United States.

By clogging the immigration courts with meritless claims, the government argues, these applicants harm asylum-seekers with legitimate cases who must wait longer to secure the protection they deserve.

Under the policy, which the administration announced on 15 July, only immigrants who have officially lost their bids for asylum in another country or who have been victims of “severe” human trafficking are permitted to apply in the United States.

Hondurans and Salvadorans have to apply for asylum and be denied in Guatemala or Mexico before they become eligible to apply in the United States, and Guatemalans have to apply and be denied in Mexico.

The policy reversed long-standing asylum laws that ensured people could seek safe haven no matter how they got to the United States. On July 16, the day the new rule went into effect – initially in the Rio Grande Valley of Texas – the American Civil Liberties Union challenged the policy in court in San Francisco.

The case in Washington was filed separately by two advocacy organisations, the Capital Area Immigrants’ Rights Coalition and the Refugee and Immigrant Center for Education and Legal Services, or RAICES.

A migrant father and daughter in Monterrey, Mexico, among the thousands attempting to reach the US but left to fend for themselves with little support (AP)

“The court recognised, as it did with the first asylum ban, that the Trump administration was attempting an unlawful end run around asylum protections enacted by Congress,” said Lee Gelernt, the ACLU lawyer who argued the case in San Francisco. The ACLU was joined by the Center for Constitutional Rights and the Southern Poverty Law Center.

The groups argued that immigration laws enacted by Congress expressly state that a person is ineligible for asylum only if the applicant is “firmly resettled” in another country before arriving in the United States.

The laws also require an asylum-seeker to request protection elsewhere only if the United States has entered into an agreement with that country and the applicant was guaranteed a “full and fair procedure” there, they said.

A Justice Department spokesman contested the argument that the rule defied the law, saying that Congress gave the attorney general and homeland security secretary license to bar certain categories of migrants. “The bar here falls well within that broad grant of authority,” he said. “The district court was wrong to conclude otherwise.”

In federal court in Washington, two advocacy groups made similar arguments against the new policy.

But that judge, Timothy J. Kelly, found that the groups did not sufficiently support their claim that “irreparable harm” would be done to the plaintiffs in the case if the policy were not blocked. While the rule would affect migrants seeking asylum, the judge said, “the plaintiffs before me here are not asylum-seekers.”

“They are only two organisations, one of which operates in the DC area, far from the southern border,” he added.

In recent years, the number of migrants petitioning for asylum has skyrocketed.

Two racist women in Burger King tell Puerto Rican manager to go back to Mexico

Migrant families and unaccompanied children have been turning themselves in to Border Patrol agents and then requesting asylum, which typically enables them to remain in the United States for years as their cases wind through the backlogged immigration courts. Only about 20 percent of them ultimately win asylum, according to the government, and many of those whose applications are rejected remain in the country unlawfully.

The administration announced the new asylum policy despite the fact that Guatemala and Mexico had not agreed to the plan, which means those countries have made no assurances that they would grant asylum to migrants intending to go to the United States.