SACRAMENTO, Calif. — Nineteen states sued on Monday over the Trump administration's effort to alter a federal agreement that limits how long immigrant children can be kept in detention.

"We wish to protect children from irreparable harm," California Attorney General Xavier Becerra said as he announced the lawsuit he is co-leading with Massachusetts Attorney General Maura Healey. Both are Democrats.

A 1997 agreement known as the Flores settlement says immigrant children must be kept in the least restrictive setting and generally shouldn't spend more than 20 days in detention.

The U.S. Department of Homeland Security said last week it would create new regulations on how migrant children are treated. The administration wants to remove court oversight and allow families in detention longer than 20 days. About 475,000 families have crossed the border so far this budget year, nearly three times the previous full-year record for families.

A judge must OK the Trump administration's proposed changes in order to end the agreement, and a legal battle is expected from the case's original lawyers.

It's not likely that U.S. District Court Judge Dolly Gee would approve the changes; it was her ruling in 2015 that extended the application of the Flores agreement to include children who came with families. She ordered the Obama administration to release children as quickly as possible.

Still, Becerra argued California has a role to play in the case because the state is home to so many immigrants.

"The federal government doesn't have a right to tell us how we provide for the well-being of people in our state," he said.

California does not have any detention centers that house migrant families. The Trump administration argued that because no states license federal detention centers, they wanted to create their own set of standards in order to satisfy the judge's requirements that the facilities are licensed.

They said they will be audited, and the audits made public. But the Flores attorneys are concerned that they will no longer be able to inspect the facilities, and that careful state licensing requirements will be eschewed.

Becerra echoed that argument, saying that removing state authority over licensing centers could allow the federal government to place centers in California or other states that don't meet basic standards of care.

Attorney General Bob Ferguson of Washington, also a Democrat, said prolonged detention will have long-term impacts on the mental and physical health of immigrant children and families.

"When we welcome those children into our communities, state-run programs and services bear the burden of the long-term impact of the trauma those children endured in detention," he said.

California on Monday also sought to halt a Trump administration effort that could deny green cards to immigrants using public benefits.

Other states joining the lawsuit are Connecticut, Delaware, Illinois, Maine, Maryland, Michigan, Minnesota, Nevada, New Jersey, New Mexico, New York, Oregon, Pennsylvania, Rhode Island, Vermont, Virginia, Washington, and the District of Columbia.