SACRAMENTO — California Gov. Gavin Newsom on Thursday signed a controversial bill to repeal a provision of state law that bans loitering for the intent to sell sex — a proposal that deeply divided Democrats in the Legislature and pitted transgender rights activists against advocates to stop human trafficking.

Anti-loitering laws have been contentious nationwide, in part because they are often vague in their definition of what constitutes as loitering, which gives police wide latitude to arrest or disperse individuals. While New York state and cities such as Seattle have repealed anti-loitering laws, California now becomes the largest state to do so.

In his signing statement released Friday, Newsom alluded to the difficult political debate around the bill, but noted that it “does not legalize prostitution.”

“It simply revokes provisions of the law that have led to disproportionate harassment of women and transgendered adults,” Newsom wrote. “While I agree with the author’s intent and I am signing this legislation, we must be cautious about its implementation. My Administration will monitor crime and prosecution trends for any possible unintended consequences and will act to mitigate any such consequences.”

Lawmakers initially passed Senate Bill 357 in September, but state Sen. Scott Wiener (D-San Francisco) delayed sending it to Newsom until June during Pride Month, in order to buy time to address concerns from the opposition and present the case for why the measure should become law.

“Everyone — no matter their race, gender or how they make a living — deserves to feel safe on our streets,” Wiener said in a statement.

The bill voids a misdemeanor law against loitering in public for the purpose of engaging in prostitution, which supporters of SB 357 said police use to disproportionately discriminate against sex workers and LGBTQ people, many of whom are Black and brown. They raised concerns that the law worsens conditions for workers and leads to unsafe and violent situations, especially against transgender women.

“This is a piece of legislation that will ensure that people are safe on the streets and that we do not continue to be harassed and oppressed by law enforcement,” said Bamby Salcedo, president and CEO of the TransLatin@ Coalition. “It is important to recognize that sex work and sex workers need to have dignity, and that we are also safe as we navigate the streets of the state of California.”

Opponents have argued that the bill takes California down the path toward full decriminalization of sex work, and that police use the loitering law to hold johns and pimps accountable for allegedly taking advantage of young women and girls.

“The bill is dangerous, and it’s the first step toward full legalization of prostitution. A false narrative was used when the bill was drafted,” Rima Nashashibi, founder and president of Global Hope 365, a nonprofit that focuses on gender-related issues, said during a news conference. “We reject the idea that decriminalizing loitering will make conditions safer for women and girls who are victims of sex trafficking.”

While the proposal comfortably passed the full Senate last fall, the Assembly approved it with only one vote to spare. Several Democrats joined Republicans in opposing the measure, while some withheld their vote.

That put more-moderate Democrats at odds not only with members of their own caucus, but with the civil liberty and LGBTQ advocacy organizations with whom they’re often aligned.

“The thing with this bill is that it really is a double-edged sword. It’s been presented by advocates, it’s been presented by organizations who are often my allies, as a way to protect our vulnerable communities, as a way to protect particularly transgender and other vulnerable individuals from harassment and discrimination,” Assemblymember Cottie Petrie-Norris (D-Irvine) said during the news conference.

“But this bill is also one with immense unintended consequences. And those unintended consequences, I believe, do put young women, young girls, and really and truly, our most vulnerable Californians at a greater risk of human trafficking.”

Petrie-Norris said she wanted her fellow lawmakers to instead find a “different approach and a different strategy” to “ensure that we can protect and lift up all Californians.”

But Ayako Miyashita Ochoa, co-director of the Southern California HIV/AIDS Policy Research Center and an adjunct professor at the UCLA Luskin School of Public Affairs, said criminalization pushes sex workers into “isolated and unsafe spaces,” with “scant evidence” of positive health outcomes.

Data instead show that criminalization of consensual sex work leads to increased risk of STIs, HIV and condomless sex, she said, and creates distrust in law enforcement.

“What we’re talking about here is moral legislation. And what we should be talking about is labor protections,” Miyashita Ochoa said. “And if we can’t give women and other folks engaged in sex trades that dignity as a worker, then we are just as bad as the people that are taking advantage.”