California lawmakers gave initial approval Monday to a measure that prevents law enforcement from cooperating with federal immigration officials, a measure that proponents said rebukes President Donald Trump for his immigration crackdown.

It makes California a statewide sanctuary for many people who are in the country illegally.

The state Senate passed the measure on a 27-12 vote, sending it to the state Assembly over the objection of opponents who said it endangers the public by shielding felons from being deported.

The bill, SB54, advanced after Senate President Pro Tem Kevin de Leon, a Democrat from Los Angeles, amended it to let state and local law enforcement notify Immigration and Customs Enforcement federal agents before convicted serious or violent felons are released from custody.

De Leon also stripped the bill of a provision that would have required a two-thirds vote. Passing the measure with a simple majority means it wouldn't take effect until Jan. 1, while the previous version would have taken effect immediately.

"We will cooperate with our friends at the federal level with serious and violent felons. But we won't cooperate or lift a finger or spend a single cent when we're talking about separating children from their mothers, mothers from their children," de Leon said. "That's not who we are as a great state."

Trump in January signed an order threatening to withdraw federal grants from jurisdictions that bar officials from communicating with federal authorities about someone's immigration status.

"By passing this today you'll be kicking the president right in the groin, and I can imagine he's going to strike back," said Republican Sen. Jeff Stone of Temecula.

The American Civil Liberties Union, the National Day Laborer Organizing Network and other supporters said the bill would give California some of the nation's strongest anti-deportation protections.

Lawmakers in the nation's most populous state also advanced two other bills that attempt to impede the president's immigration policies. They sent the Assembly a bill, SB6, that would provide $12 million to pay lawyers for immigrants facing deportation, and another measure, SB31, that would bar state officials from sharing data if the federal government creates a Muslim registry.

California is home to an estimated 2.3 million immigrants who do not have legal authorization. San Francisco, which is among cities with its own sanctuary law, is suing over Trump's executive order.

The statewide sanctuary bill, SB54, would bar police and sheriffs from arresting or detaining people just for immigration violations unless a judge issues a warrant. De Leon's recent amendments also make it easier for local law enforcement to hand over criminals to federal immigration officials if they were previously deported for a violent felony.

State and local law enforcement agencies would not be able to help investigate immigration violations or inquire about someone's immigration status.

The measure also seeks to limit immigration enforcement activities in schools, courthouses and other public facilities.

"If we don't control our borders, we cease to be a nation," objected Sen. Ted Gaines, a Republican from El Dorado Hills. "We cannot become a beacon of lawlessness."

Earlier amendments make it clear that local law enforcement can still participate in task forces with federal immigration agents, so long as the task force's primary purpose is not immigration enforcement.

Even some Democrats said they are concerned the bill still bars state and local officials from turning over criminals convicted of certain sexual or violent crimes. But they supported the measure as it moved forward.

"Overwhelmingly this bill is about people who are just trying to live their lives. People who are living in fear right now," said Sen. Scott Wiener, a Democrat from San Francisco.

Supporters of the bill want to prohibit state or local police from being deputized to help find those in the country illegally. They say police cooperation with immigration authorities can increase crime and harm victims by making victims or witnesses fearful of reporting crimes for fear they will be deported.

"This is an acknowledgement of the cultural and economic contributions made to our great state by immigrants from all over the world," de Leon said outside the Senate chamber after the vote. "And it is a rejection of President Trump's false and cynical portrayal of undocumented immigrants as a lawless community."

There was no immediate response from the White House.