WASHINGTON — The Trump administration announced a new rule Thursday that would allow immigrant children with their parents to be held in detention indefinitely, upending a ban on indefinite detention that has been in place for 20 years.

The rule, proposed by the departments of Homeland Security and Health and Human Services, goes into effect in 60 days and will allow Immigration and Customs Enforcement (ICE) to keep children with their mothers in detention facilities while their cases for asylum play out in court.

A DHS official said the average length of stay for adults with pending court cases is currently 39 days. However, court backlogs can drag out the time an immigrant must wait in detention for a court hearing.

Until now, children have been released with their parents after 20 days. Earlier this year, the Trump administration sought to get around that rule by separating parents from their children and holding parents in detention while children were placed in the care of HHS.

A DHS official speaking on the condition of anonymity said the purpose of the rulemaking is to terminate the 1997 Flores settlement agreement that said children could not be held in detention longer than 20 days. The result may mean the issue is taken to appellate courts or even the Supreme Court.

Officials argue that the rulemaking is legal because they will be holding children in ICE facilities that have been evaluated by third parties.

"Under this proposed rule, HHS would implement the Flores Settlement Agreement and our duties under the law to protect the safety and dignity of unaccompanied alien children in our custody," said HHS Secretary Alex Azar. According to a DHS statement, the evaluations will "satisfy the basic purpose" of the Flores settlement agreement by keeping children safe.

DHS Secretary Kirstjen Nielsen said in a statement that the rulemaking is necessary to enforce immigration laws.

"Today, legal loopholes significantly hinder the Department's ability to appropriately detain and promptly remove family units that have no legal basis to remain in the country," said Nielsen. "This rule addresses one of the primary pull factors for illegal immigration and allows the federal government to enforce immigration laws as passed by Congress."