California joined San Francisco on Monday in taking legal action challenging a Trump administration threat to withhold federal public safety grants from sanctuary cities that refuse to cooperate in deportations.

A lawsuit filed by Attorney General Xavier Becerra makes California the first state in the country to take on the U.S. Justice Department’s plan to pull the grant money. San Francisco filed its own lawsuit Friday, the second such legal action it has filed against the Trump administration.

Becerra said the state’s lawsuit, filed in U.S. District Court in San Francisco, was based on the same grounds as the city’s — that President Trump and his administration can’t withhold money from a congressionally approved program without Congress’ agreement

“We abide by federal law. We respect the Constitution. The federal government should do the same,” Becerra said at a news conference with San Francisco City Attorney Dennis Herrera at City Hall.

Becerra’s lawsuit, if successful, could help lay the foundation for state legal efforts against the administration should the Legislature approve a sanctuary-state bill that would prohibit local police officers and sheriff’s deputies from enforcing federal immigration laws. Gov. Jerry Brown has said he has concerns about the measure, which some law enforcement officials strongly oppose.

The Trump administration has repeatedly sought to compel sanctuary cities to cooperate with immigration authorities by threatening to withdraw their federal funding. In April, San Francisco and Santa Clara County persuaded a federal judge to block a key section of an executive order issued by Trump that would withhold federal funding for sanctuary cities, calling the measure unconstitutional and an overreach by the federal government. The administration is appealing that decision.

The new lawsuits concern the Edward Byrne Memorial Justice Assistance Grant Program, which provides money that local governments use to buy equipment such as police cars and fund a variety of public safety efforts, including jail diversion initiatives, adult alternative courts and social work services.

More for you News Hillary Clinton wants to be a lay preacher

Each year, San Francisco receives about $1.5 million from the grant program. About a third of that comes from the federal government, and the rest from the state.

Last month, U.S. Attorney General Jeff Sessions announced the Justice Department would withhold Byrne grants to sanctuary cities unless their officials agreed to work more closely with immigration officers. Specifically, San Francisco and other sanctuary cities would have to grant jail access to federal immigration officials to interrogate suspects. They would also have to provide federal officials with 48 hours’ notice of the impending release of people wanted for immigration-related questioning.

In response to the latest lawsuits, a Justice Department spokesman said via email that San Francisco and other California cities “have already experienced the devastating effects that sanctuary policies have on their citizens.” He said it was “especially disappointing that state leaders would take steps to limit cooperation between local jurisdictions and immigration authorities that are trying to keep Californians safe.”

Trump made a campaign issue out of the 2015 killing of Kathryn Steinle, allegedly by a Mexican citizen who had been deported several times before being shipped from a federal prison to San Francisco to face possible prosecution for a marijuana charge. Prosecutors dropped the charge, and the Sheriff’s Department let him go without turning him over to immigration officials.

San Francisco Mayor Ed Lee said it was the Trump administration that was endangering public safety “in the name of politics” by threatening to withhold the grant money. “San Francisco will not be intimidated by the federal government’s threats,” he said in a statement.

At Monday’s news conference, Herrera called the administration’s efforts to pressure sanctuary cities into complying with immigration officers “an end-run around the Constitution” that vilifies immigrants and punishes cities that prioritize public safety services “over splitting up hardworking families.”

“The Department of Justice does not have authority from Congress to impose these conditions (on the grants), and for good reason.” Herrera said.

Dominic Fracassa is a San Francisco Chronicle staff writer. Email: DFracassa@sfchronicle.com Twitter: @dominicfracassa