Guatemalan men who were deported from the United States board a bus after arriving in Guatemala City on July 16. (Moises Castillo/AP)

A federal judge in San Francisco temporarily blocked a new Trump administration policy Wednesday that sought to bar Central Americans and other migrants from requesting asylum at the southern border, saying the federal government’s frustrations with rising border crossings did not justify “shortcutting the law.”

The policy aimed to curtail Central American migration across the southern border by requiring asylum seekers to apply in countries they had passed through on the way to the United States, particularly Mexico or Guatemala.

U.S. District Judge Jon S. Tigar, who halted another version of the Trump administration’s asylum ban last year, said a “mountain” of evidence showed that migrants could not safely seek asylum in Mexico. He said the rule likely violated federal law in part by categorically denying asylum to almost anyone crossing the border. U.S. law generally allows anyone who sets foot on U.S. soil to apply for asylum.

Tigar issued a preliminary injunction blocking the July 16 policy and ordered the government to restore the existing system. He wrote that the “government rightly notes that the strains on this country’s immigration system have only increased since the fall of 2018,” but he said that did not authorize them to bypass Congress.

“The public undoubtedly has a pressing interest in fairly and promptly addressing both the harms to asylum applicants and the administrative burdens imposed by the influx of persons seeking asylum,” Tigar, an Obama administration appointee in the U.S. District Court for the Northern District of California, wrote in his 45-page ruling. “But shortcutting the law, or weakening the boundary between Congress and the Executive, are not the solutions to these problems.”

The American Civil Liberties Union, which argued the case in court on behalf of several nonprofits, cheered the ruling and said the Trump administration’s policy would have effectively ended asylum at the southern border.

“The court recognized, as it did with the first asylum ban, that the Trump administration was attempting an unlawful end run around asylum protections enacted by Congress,” ACLU lawyer Lee Gelernt said in a statement.

Tigar’s ruling followed an hour-long hearing Wednesday in San Francisco and a short-lived legal victory for the Trump administration over the same policy, in a different lawsuit in Washington.

U.S. District Judge Timothy J. Kelly, a Trump appointee, declined to halt the policy, setting up a potential race to federal appellate courts over one of the administration’s key migration initiatives.

President Trump immediately hailed the D.C. decision as a victory, telling reporters outside the White House that the decision “helps us very much at the border.”

“So the asylum is a very big ruling. That was a tremendous ruling today,” Trump said. “We appreciate it. We respect the courts very much.”

Neither judge ruled on the merits of the cases, and the Justice Department is expected to appeal Tigar’s ruling.

A Justice Department spokesman said in response to the ruling that Congress granted the attorney general and the Department of Homeland Security broad authority to bar “certain categories” of asylum seekers.

“The district court was wrong to conclude otherwise, to second-guess the agencies’ expert policy judgment, and to halt this critical measure on a nationwide basis — particularly on the very same day that another district judge, faced with a legal challenge to this rule by virtually indistinguishable organizations, refused to issue such nationwide injunction relief,” the statement said.

Tigar wrote that the Trump administration failed to show that forcing asylum seekers to apply in Mexico is a “feasible alternative” and said during the hearing that government lawyers did not provide a “scintilla” of evidence to suggest that Guatemala could absorb them, either.

Instead, he wrote, human rights organizations documented “in exhaustive detail” how asylum seekers in Mexico are subjected to violence and abuse from government officials and others, denied their rights, and even “wrongly returned” to nations they fled. The United Nations High Commissioner for Refugees said Mexico has “strong obstacles” to applying for asylum, including the lack of proper screening procedures and other measures.

“Yet, even though this mountain of evidence points one way, the agencies went the other — with no explanation,” Tigar said of the rule, published by the Justice Department and the Department of Homeland Security.

Tigar noted that his ruling simply restores the asylum system to the one Congress authorized in federal law.

“While the public has a weighty interest in the efficient administration of the immigration laws at the border, it also has a substantial interest in ensuring that the statutes enacted by its representatives are not imperiled by executive fiat,” Tigar wrote.

He said the injunction “would vindicate the public’s interest — which our existing immigration laws clearly articulate — in ensuring that we do not deliver aliens into the hands of their persecutors.”

Plaintiffs in both cases — nonprofits serving immigrants — filed the legal challenges hours after the Justice Department and Department of Homeland Security published a rule July 16 barring most migrants from filing asylum claims if they traveled through Mexico or another country where they could have sought refuge.

The White House has contended that migrants are surging to the southern border with children and filing asylum claims to ease their paths to quick release so they can work in the United States. Asylum filings have nearly quadrupled in the past five years; fewer than 20 percent of Central American applicants prevail in immigration court. Advocates for immigrants argue that they are fleeing violence, poverty and hunger and should be given the chance to plead their cases.

The Southern Poverty Law Center, the Center for Constitutional Rights and others joined the ACLU in seeking the injunction in the U.S. District Court for the Northern District of California. The court falls under the U.S. Court of Appeals for the 9th Circuit, which has considered most of the major immigration legal challenges against the Trump administration.

Justice Department lawyer Scott Stewart said during Wednesday’s hearing in Tigar’s courtroom that the asylum policy is one of multiple efforts to slow the influx of migrant families, and said they are “important in negotiations” to persuade Mexico and other countries to “share the burdens” of mass migration.

Mexico intensified immigration enforcement in June and agreed to host thousands more asylum seekers while their immigration cases are pending in the United States after the White House threatened to hit the country with export tariffs. Border apprehensions slumped in June and July — typically slower months because of the intense heat — but it is unclear whether the drop is sustainable in the longer term.

“Pressure on Mexico works,” Stewart said. “It’s not always an ‘ask nicely and hope somebody helps you out.’ ”

In November, Tigar struck down a Trump administration policy that barred immigrants from seeking asylum if they crossed the border illegally, saying the policy violated federal law.

The U.S. Court of Appeals for the 9th Circuit later upheld Tigar’s decision.

In court Wednesday, the Justice Department lawyer noted that Kelly, the federal judge in Washington, had just rejected a similar request to halt the new asylum policy. The nonprofits in that case, the Capital Area Immigrants’ Rights Coalition of Washington and the Texas-based Refugee and Immigrant Center for Education and Legal Services, had argued that they would suffer harm by serving fewer migrants.

Kelly ruled that the groups had failed to show how many of their clients would be affected by the change, saying that “there is just nothing in the record to suggest how many individuals, if any, fall into that category.”

But Tigar said each judge must render his or her own decision: “We have the appellate courts to sort this out for us.”

Colby Itkowitz contributed to this report.