Brendan Mcdermid / Reuters

A federal judge has ordered the Trump administration to end separations for most migrant families at the border, and to reunify parents and children who were already separated within the next month, with limited exceptions.

In a ruling late Tuesday, US District Judge Dana Sabraw wrote that the federal government had adopted a practice of separating families without “any effective system or procedure” for tracking children, for allowing parents and children to communicate while they were apart, or for reuniting families once a parent’s criminal case was over. He called it a “startling reality.”

“The facts set forth before the Court portray reactive governance — responses to address a chaotic circumstance of the Government’s own making,” Sabraw wrote. “They belie measured and ordered governance, which is central to the concept of due process enshrined in our Constitution.”

Sabraw authorized the case, brought by the American Civil Liberties Union in federal court in San Diego, to proceed as a class action. The lawsuit now covers all adults in immigration custody — including migrant parents who entered the United States at an official port of entry as well as those who did not — who have a child who has been will be separated and placed into government custody.

Under Sabraw’s order, the federal government is now blocked from separating families while a parent is in immigration detention, absent evidence that a parent is unfit or poses a danger to the child, or that the parent has waived being held together. He also ordered the government to reunite all class members with their children within 30 days, or 14 days if a child was younger than five years old, and to allow parents to contact separated children within 10 days.

“This ruling is an enormous victory for parents and children who thought they may never see each other again. Tears will be flowing in detention centers across the country when the families learn they will be reunited,” Lee Gelernt, deputy director of the ACLU’s Immigrants’ Rights Project, said in a statement.

A Justice Department spokesperson did not immediately return a request for comment.

In concluding that the plaintiffs would suffer irreparable harm without action from the court, Sabraw quoted statements filed by parents describing their experiences of separation from their children. The record, Sabraw wrote, showed that “the separations at issue have been agonizing for the parents who have endured them.”

The two lead plaintiffs in the case are referred to only as “Ms. L” and “Ms. C.” According to the lawsuit, Ms. L is a citizen of the Democratic Republic of the Congo, who entered the United States with her then-six-year-old daughter in November 2017 through a port of entry at the US-Mexico border in California. Ms. L sought asylum on religious persecution grounds. After several days of being detained together, she and her daughter were separated for several months until Ms. L was released pending a decision on her asylum application. Federal officials returned Ms. L’s daughter to her after confirming their relationship via a DNA test.

Ms. C is a Brazilian citizen and entered the United States “between ports of entry” with her son, who was 14 years old at the time, according to court papers. They were separated while she was charged and convicted of entering the country illegally, and were not reunited until after Ms. C had served…