The Trump administration’s latest attempt to stop Central American migrants from seeking asylum in the United States ran into a familiar roadblock Wednesday: a federal judge in San Francisco, who said the new policy flies in the face of long-standing immigration laws.

People fleeing violence and hardship in their homeland are allowed to seek U.S. refuge under laws aimed at “ensuring that we do not deliver aliens into the hands of their persecutors,” U.S. District Judge Jon Tigar said in a nationwide injunction blocking enforcement of the rules, which took effect July 16.

Under those laws, he said, the government cannot deny asylum simply because the applicant passed through another country on the way to the U.S., unless that country has been found to be a safe haven for refugees. By barring asylum to all who enter another nation without seeking refuge there — such as Mexico, with dangerous conditions and an overwhelmed asylum system — the Trump administration “turns its back on those requirements,” Tigar said.

The dispute is headed for higher courts, possibly the Supreme Court. Earlier Wednesday, a federal judge in Washington, D.C., ruled in a separate lawsuit, allowing the asylum policy to remain in effect, and questioning the standing of immigrant-rights groups to challenge it.

For now, Tigar’s injunction takes precedence, halting enforcement of the new rules. At a hearing earlier Wednesday, he observed, “We have the appellate courts to sort this out for us.”

The ruling is “an important victory for incredibly vulnerable individuals and families from besieged Central American countries,” said attorney Melissa Crow of the Southern Poverty Law Center, one of the legal groups representing immigrant advocates in the San Francisco case. The immigrant-rights groups were represented by lawyers led by the American Civil Liberties Union.

President Trump’s Justice Department criticized the ruling.

The new policy was needed “to address the crisis on the southern border” by limiting asylum to “those who have nowhere else to turn,” the department said. It said Tigar was wrong to “second-guess the (administration) agencies’ expert policy judgment,” particularly in view of the earlier ruling allowing enforcement.

That decision was issued by U.S. District Judge Timothy Kelly, a Trump appointee. According to published accounts of his ruling from the bench, Kelly said two organizations that challenged the new policy had failed to show how many of their clients, if any, would be harmed, or how their services would suffer as a result.

Tigar, appointed by President Barack Obama, blocked another Trump administration rule in November that would have barred asylum for anyone crossing the Mexican border except at designated ports of entry. Trump then derided Tigar as an “Obama judge,” drawing rebukes from both U.S. Supreme Court Chief Justice John Roberts and California Chief Justice Tani Cantil-Sakauye.

A federal appeals court upheld that ruling, and the Supreme Court denied review of the administration’s appeal.

Asylum allows an immigrant to remain in the U.S., obtain a work permit and eventually apply for citizenship. It is granted to non-citizens who can show a “well-founded fear of persecution” in their home country for reasons such as race, religion, political views or sexual orientation. Migrants fleeing domestic violence and gang violence can also seek asylum under court rulings rejecting then-Attorney General Jeff Sessions’ attempt to eliminate their eligibility.

The administration’s policy categorically denied asylum to anyone who had passed through another country on the way to the United States. The only exceptions were for victims of human trafficking, and for migrants who had unsuccessfully sought asylum in the country they entered. The effect was to eliminate asylum for anyone from Central America except those traveling by boat or plane.

Tigar said federal laws allow a categorical denial of asylum only if the applicant has received an “offer of resettlement” from another country in which he or she would not face persecution, or has passed through a country that provides protection from persecution and a “full and fair procedure” for determining asylum, under a formal agreement with the United States.

The U.S. has only one such agreement, with Canada, and has recently tried and failed to negotiate agreements with Mexico and Guatemala, the judge noted. While the Justice Department argued that requiring migrants to seek asylum in Mexico was a “feasible alternative” to the U.S., Tigar said, the evidence is to the contrary: Mexico’s asylum system is flooded with applications, its detention centers are full beyond capacity, and, as the group Human Rights First documented, “many refugees face deadly dangers in Mexico.”

Tigar also said the administration had failed to justify putting its new rules into effect immediately rather than allowing 30 days of public comment, as required for most government regulations. The Justice Department said issuing advance notice would cause a surge of border-crossings within the 30-day period, but Tigar said the department presented virtually no evidence to support its contention.

Bob Egelko is a San Francisco Chronicle staff writer. Email: begelko@sfchronicle.com Twitter: @BobEgelko