(Reuters) - A U.S. judge on Monday halted the Trump administration’s policy of sending some asylum seekers back across the southern border to wait out their cases in Mexico, stopping a program the government planned to expand to stem a recent flood of migrants.

The ruling is slated to take effect on Friday, according to the order by U.S. District Judge Richard Seeborg in San Francisco. The preliminary injunction will apply nationwide.

In a late night tweet, U.S. President Donald Trump said, “A 9th Circuit Judge just ruled that Mexico is too dangerous for migrants. So unfair to the U.S. OUT OF CONTROL!”

The program was launched in January and was one of many policies aimed at slowing rising numbers of immigrants arriving at the border, many of them families from Central America, that swelled last month to the highest in a decade.

Because of limits on how long children are legally allowed to be held in detention, many of the families are released to await U.S. immigration court hearings, a process that can take years because of ballooning backlogs.

The Trump administration said last week it planned to expand the program of sending some migrants to wait out their U.S. court dates in Mexican border cities under a policy known as Migrant Protection Protocols, or MPP.

The government argued MPP was needed because so many asylum seekers spend years living in the United States and never appear for their court hearings before their claim is denied and an immigration judge orders them to be deported.

Seeborg said the Immigration and Nationalization Act, however, does not authorize the government to return asylum seekers to Mexico the way the government has applied it.

He also said the policy lacks safeguards to protect refugees from threats to their life or freedom.

Slideshow ( 8 images )

Justice Department data show that while the percentage of immigration court cases completed “in absentia” - when the foreign citizen fails to show - has risen in recent years, the majority of immigrants show up for their hearings.

A U.S. Department of Justice spokesman declined to comment on Monday’s ruling. The White House did not immediately respond to a request for comment.

The Mexican foreign ministry considers the ruling “an internal decision” of the United States, a spokesman said.

Seeborg said the government shall permit the 11 plaintiffs in the case to enter the United States beginning on Sunday. He said the government still retained the right to detain the asylum-seekers pending the outcome of their case.

The ruling can be appealed, and the government could seek a stay of the injunction until the appeals process runs its course.

LAWYERS, MIGRANTS GRATIFIED

Still, lawyers for migrants were gratified by the decision.

“This is a great ruling,” said Judy Rabinovitz, a lawyer with the American Civil Liberties Union, which was one of the groups that brought the case.

Slideshow ( 8 images )

“This is what they were planning on implementing on a large scale. That would have been a complete game changer in the way our asylum system works,” she said.

Rabinovitz said the groups that brought the lawsuit needed to discuss what could be done for the hundreds of refugees who are awaiting their cases in Mexico.

She said as their cases are heard, they will be returned to the United States, but that could take months.

The plaintiffs include legal service organizations and migrants who fled Guatemala, Honduras and El Salvador to escape what they said was extreme violence, rape and death threats.

Gabriela Orellana, 26, an asylum seeker from El Salvador who was scheduled to have her first hearing on Tuesday, was delighted by news of the judge’s ruling.

“I’m crying from happiness,” she told Reuters. She is not one of the plaintiffs in the case.

Orellana said she fled El Salvador with her 8-year-old daughter and 6-year-old son after she was shot by a gang member. She has been in Tijuana since January and has waited nearly two months for her first interview with U.S. immigration authorities.

Others in Tijuana were more cautious.

“Will I be allowed to go or do I have to stay?” asked Veronica Galdamez, who said she fled San Salvador in 2018 after gang members stole her food cart and, pointing a gun at her, told her she had 24 hours to get out of the city.

“I feel real happiness, but also uncertainty, because I don’t know if this applies to me,” Galdamez said.

MPP was based on a decades-old law that says migrants who enter from a contiguous country can be returned there to wait out their deportation case, although the provision had never been used in the way the administration has applied it.

Civil rights groups sued, arguing the policy violated U.S. and international law by returning refugees to dangerous border towns where they would be unable to get legal counsel or notices of hearings.

Kirstjen Nielsen resigned as Secretary of Homeland Security, the department that oversees immigration, on Sunday.

A congressional official familiar with the matter said some in Congress believe Trump forced out Nielsen in part because she was trying to obey laws on treatment of refugees, granting of amnesty and separation of families.

(This story corrects spelling of last name of migrant in paragraphs 25-26 to Galdamez, not Galdames)