California Gov. Jerry Brown and the state Senate leader said Monday they've agreed to changes in proposed legislation that would further restrict interactions between law enforcement officers and federal immigration agents.

The agreement came on the same day the state sued the Trump administration over its decision to end a program that shields young immigrants from deportation.

Senate President Pro Tem Kevin de Leon, D-Los Angeles, agreed to changes demanded by Brown following fierce opposition from sheriffs and other law-enforcement officials.

The bill would still prohibit state and local police from asking about people's immigration status or enforcing federal immigration laws.

However, following Monday's changes, it would preserve the ability of law officers to cooperate with federal task forces as long as the task force doesn't specifically work on immigration enforcement.

Police and jail officials would be able to notify U.S. immigration agents if they detain people with convictions for some 800 crimes, including serious felonies, battery, assault and sexual crimes.

Immigration agents would still be allowed to interview immigrants in jail, and immigration agents would not be barred from accessing state databases.

"This bill protects public safety and people who come to California to work hard and make this state a better place," Brown said in a statement.

Brown and de Leon reached their agreement in the last week of the legislative year. The Assembly and Senate must approve the measure by Friday or delay action until next year.

U.S. Immigration and Customs Enforcement had no immediate comment.

California already has some of the most protective laws in the country for immigrants detained by law enforcement. The state has limited the ability of police to detain immigrants for federal deportation agents since 2014, and requires jailers to inform inmates if agents are trying to detain immigrants.

Illinois recently passed even more protective legislation that bars law enforcement from detaining immigrants solely for deportation, said Shiu Ming Cheer, senior staff attorney at the National Immigration Law Center.

A handful of cities including Chicago and San Francisco, meanwhile, are refusing to cooperate with new federal requirements for tougher immigration enforcement, prompting the Trump administration to threaten to withhold funding.

Kern County Sheriff Donny Youngblood, a critic of the initial state bill, said sheriffs would be discussing the latest version on a call Tuesday and declined to discuss the details. He noted that ICE generally seeks cooperation on people convicted of major crimes.

Immigrant rights groups held a noisy rally in the Capitol last week urging Brown and de Leon not to back off from the strict immigrant protections de Leon originally proposed in the wake of Donald Trump's election as president.

But the activists generally praised the compromise with Brown.

"We hope that it will serve as a model for other states and encourage them to adopt similar protections," said Jenny Pasquarella, immigrant rights director for the American Civil Liberties Union of California. "This is where the dragnet is."

The legislative deal was announced the same day that California Attorney General Xavier Becerra said he's filing a lawsuit over the Trump administration's decision to phase out the Deferred Action for Childhood Arrivals program, which protects young immigrants living in the U.S. illegally from deportation.

The lawsuit's legal arguments largely mirror those already filed in a lawsuit last week by 15 other states and the District of Columbia. Attorney generals for the states of Maine, Maryland, and Minnesota joined California's lawsuit.

More than 200,000 of the 800,000 participants in the Deferred Action for Childhood Arrivals program live in California.

The University of California has also filed a legal challenge to ending the program.

Also on Monday, Mexico Foreign Secretary Luis Videgaray said he and other Mexican diplomats are urging members of Congress to make the DACA program permanent and that he is not expecting an immediate influx of hundreds of thousands of young people back to Mexico.

Associated Press writers Sudhin Thanawala in San Francisco, Amy Taxin in Orange County, Kathleen Ronayne in Sacramento and Marine Villeneuve in Augusta, Maine, contributed reporting.