A federal appeals court in California halted the Trump administration’s “Remain in Mexico” asylum policy on Friday, removing one of the key tools the president has used to curb mass migration across the southern U.S. border.

The ruling was in effect for only a few hours, however, as the judges later granted a Trump administration request for an emergency stay “pending further order of this court.” Justice Department lawyers said in court filings that 25,000 migrants have been ­waiting in Mexico and argued that they feared the ruling would lead to an influx on the southern ­border.

The program — officially known as the Migrant Protection Protocols, or MPP — has required tens of thousands of migrants to cross back into Mexico to await their U.S. asylum hearings, part of an effort to limit access to U.S. soil and to deter people from attempting the journey north to the United States. After more than 470,000 parents and children crossed into the United States last fiscal year, with most quickly freed into the United States amid a massive immigration court backlog, the administration implemented MPP to stop that practice.

The MPP program stranded migrants in Mexican border towns without the promise of entry into the United States, and it evolved into one of the administration’s most heavily used policies. It played a central role in stemming the record flow of border crossings, and Trump administration officials warned Friday that blocking the program risked another influx, citing concerns that smugglers and Central American migrants would continue to exploit legal loopholes to gain entry.

In its initial ruling Friday, the panel of the U.S. Court of Appeals for the 9th Circuit ruled 2 to 1 to reinstate a district court judge’s preliminary injunction that stopped MPP, saying that the policy violates federal law and “should be enjoined in its entirety.” The two judges in the majority agreed with immigration advocates who argued that pushing Central Americans back into Mexico could put asylum seekers in grave danger, as they were forced to wait in Mexican cities where they could continue to face persecution, in contravention of the long-held American ideal of offering sanctuary to the oppressed.

Chad Wolf, the acting secretary of the Department of Homeland Security, called the injunction “grave and reckless” and said the DHS is working with the Justice Department to appeal the ruling. He said border officials would apply “a range of other effective tools” to prevent migrants from crossing the border and being released into the United States. Officials said in court filings that they planned to file a petition in the case with the Supreme Court.

“MPP has been a game-changer in the U.S. government’s efforts to address the ongoing crisis at the southwest border,” he said in a statement late Friday. “By implementing MPP we have also effectively reduced the incentive for smugglers and traffickers to use children in their illicit cross-border activity. Should this ruling stand, the safety and security of our border communities, international relationships and regional stability is at risk.”

Judges Richard A. Paez and William A. Fletcher, both appointed by President Bill Clinton, agreed with a lower-court judge in California that MPP probably violated federal immigration law by ousting undocumented asylum seekers who should be allowed to apply for protection in the United States. The judges also said the program probably vio­lated the administration’s “non-refoulement” obligations under international and domestic law, which prohibit the government from sending people to countries where they face danger. The 57-page ruling cited asylum seekers who feared kidnapping, threats and violence in Mexico.

“There is a significant likelihood that the individual plaintiffs will suffer irreparable harm if the MPP is not enjoined,” Fletcher wrote in the opinion. “Uncontested evidence in the record establishes that non-Mexicans returned to Mexico under the MPP risk substantial harm, even death, while they await adjudication of their applications for asylum.”

Judge Ferdinand F. Fernandez, a President George H.W. Bush appointee, dissented, arguing that the panel should have adhered to a prior appeals court decision that allowed MPP to take effect.

The Trump administration had been declaring near-victory in stemming irregular migration just weeks ago, in part because of MPP’s success, and the 9th Circuit’s decision stops the policy along the southern border.

The Justice Department issued a statement Friday saying that the decision “once again highlights the consequences and impropriety of nationwide injunctions.”

“The Trump administration has acted faithfully to implement a statutory authority provided by Congress over two decades ago and signed into law by President Clinton,” the statement said. “The Ninth Circuit’s decision not only ignores the constitutional authority of Congress and the administration for a policy in effect for over a year, but also extends relief beyond the parties before the Court.”

The Department of Homeland Security instructed asylum officers to “immediately cease all MPP processing,” according to a federal official with direct knowledge of an email message sent to the officers. The asylum officers’ labor union had filed a brief in the MPP case arguing that the policy threatened migrants’ lives and is “fundamentally contrary to the moral fabric of our Nation.”

Judy Rabinovitz, special counsel in the American Civil Liberties Union’s Immigrants’ Rights Project, who argued the case in court, hailed the initial decision and called the court’s stay later Friday “a temporary step” that “does not change the fact that courts have ruled multiple times against this illegal policy.”

“We will continue working to permanently end this unspeakably cruel policy,” she said in a statement.

Mark Morgan, the acting commissioner of Customs and Border Protection, said in a tweet after the court stayed its ruling Friday night that the agency immediately reinstated the MPP.

Along the Mexican side of the nearly 2,000-mile border, where tens of thousands of migrants are hunkered down in shelters, apartments and tent camps, migrants scrolled through social media as lawyers waited for the Trump administration to say whether it would allow them back into the United States.

“I’ve been reading about the suspension online and trying to understand, but what does it mean for my case?” said Daniel, an HIV-positive 20-year-old political activist from Venezuela who says he fled threats under the government of Nicolás Maduro. He has lived in a small apartment in Piedras Negras since October while awaiting a hearing in his asylum case. “What happens to people already under MPP?”

Immigration lawyers said they fear that the Justice Department will swiftly appeal to the U.S. Supreme Court, as it did to lift a similar injunction in January and to implement a “public charge” rule that bars low-income foreigners from immigrating to the United States.

Lawyers say they are monitoring border checkpoints to ensure that the U.S. government does not return migrants to Mexico, and some prepared to escort migrants to the border with the hope that the Department of Homeland Security will let their clients in.

Karla Vargas, a lawyer with the Texas Civil Rights Project, said that for now the group is advising migrants to “stay calm while we figure out the best way to proceed.”

Vargas said the ruling clearly establishes that MPP is illegal and that those sent to Mexico under the program have a right to enter the United States to pursue their asylum proceedings. But she said it is unclear when the ruling will take effect and what window migrants will have to exercise the rights she says they have.

The Trump administration has been working to reduce its reliance on MPP in recent months by fast-tracking deportation hearings and sending about 700 migrants from Central America by airplane to Guatemala as part of an agreement that allows them to seek asylum there instead. The number of people waiting in Mexican border cities for U.S. immigration court dates has dwindled, in part because would-be migrants in Central America said they were not making the trek to the U.S. border in the first place, given how unlikely it would be that they would gain entry.

It is unclear whether the court’s decision could spur another surge in U.S.-bound migration by Central Americans. It is possible that many people waiting in Mexico for U.S. court hearings could try to reenter the United States in coming days.

“I wouldn’t say that access to the asylum system in the United States is assured because of this injunction, because they’ve already put all these other programs in place to restrict that,” said Erika Pinheiro, the litigation and policy director at Al Otro Lado, a nonprofit organization and one of the plaintiffs in the MPP lawsuit. “All that said, MPP is a horror show of human rights violations. The less people subject to it the better.”

The ruling came on the same day Mexico announced its first coronavirus case — a traveler returning from Italy — raising potential fears about what a run on the U.S. border could mean. Sanitary conditions are abysmal in the squalid border camps where thousands of would-be asylum seekers are waiting. Human Rights First, an advocacy group, said it has documented more than 1,000 reports of murder, rape and kidnapping, including of children, among those forced into Mexico under MPP.

One former DHS official said the court decision could prompt the White House to invoke emergency executive powers to impose even tighter restrictions on asylum seekers at the border by citing a public health emergency involving the coronavirus. One legal provision, known as “Return to Territory,” gives U.S. border officials broad powers to compel a foreign national to go back to Mexico or Canada if that person is deemed inadmissible to the United States.

The same three-judge panel issued a separate 3-to-0 ruling Friday blocking Trump’s first asylum restriction, which aimed to bar migrants who crossed the border illegally from seeking asylum. The policy was temporarily halted in 2018. Trump blasted the lower-court jurist in the case as an “Obama judge,” prompting a public rebuke from U.S. Chief Justice John G. Roberts Jr., who voted with the Supreme Court’s four liberal justices months later to let the injunction stand.

Roberts and other conservative justices have since allowed other Trump policies to unfold despite pending lawsuits against them.

After MPP officially began in January 2019, it became a central aspect of the Trump administration’s bulwark against irregular migration. A federal judge in California initially halted the program, but in May, a three-judge panel on the 9th Circuit allowed it to resume until another set of judges could hear arguments on its legality.

The MPP program was expanded in June when Mexico agreed to host thousands of migrants and to crack down on smugglers after Trump threatened to impose tariffs on Mexico’s exports to the United States.

Approximately 60,000 migrants from countries including Cuba, Honduras, Guatemala, El Salvador and Venezuela have been sent back to Mexico to wait until their asylum cases can be heard in the United States. Mexican officials said many of those sent back ultimately gave up and went home.

Homeland Security officials have credited MPP and other policies with a more than 70 percent drop in the number of migrants taken into custody at the border since the peak of 144,000 in May.

Advocates reported after the ruling that migrants were beginning to line up at border checkpoints to try to reenter the United States.