Because there are more than one million cases pending in immigration court, it often takes years for cases to be completed. By then, administration officials argue, many migrants have skipped court dates and gone into the shadows, living illegally in the United States.

“The Flores settlement agreement remains in effect and has not been terminated,” Judge Gee, an appointee of President Barack Obama, wrote in a two-page order.

She said the new regulations “fail to implement and are inconsistent with” the terms of the agreement, which the government must now continue to comply with.

The ruling is likely to be appealed, and the Supreme Court could ultimately be asked to weigh in.

In a statement late Friday, the White House said that the ruling “perpetuates the loophole that this same judge created, which has been exploited by criminal cartels to smuggle children across the United States Southern Border — often resulting in their physical and sexual abuse.”

“For two and a half years, this administration has worked to restore faithful enforcement of the laws enacted by Congress, while activist judges have imposed their own vision in the place of those duly enacted laws,” the statement said. “The Flores 20-day Loophole violates Congressional removal and detention mandates, creating a new system out of judicial whole cloth. This destructive end-run around the detention and removal system Congress created must end.”

Administration officials had said that the new regulations would fulfill the Flores agreement’s provisions for ensuring that children in the government’s custody are “treated with dignity, respect and special concern for their particular vulnerability.”

But lawyers for the groups who sued on behalf of migrant children said that they did not fulfill the requirements. If adopted as written, they warned in court filings, the new rules would “strike a mortal blow to crucial rights and protections that the settlement confers on vulnerable children.”