SACRAMENTO, Calif. — California lawmakers on Thursday approved legislation that would bar most law enforcement officers from covering their faces while conducting official duties, a move driven by public concern over masked federal agents who have participated in recent immigration raids in Los Angeles.

The bill, passed by the Democratic-controlled Legislature, would prohibit neck gaiters, ski masks and other facial coverings for local and state officers as well as federal agents while they carry out official business. It includes exceptions for undercover operatives, medical masks such as N95 respirators, and tactical gear used for officer safety. Gov. Gavin Newsom has about a month to decide whether to sign the measure into law.

Supporters said the legislation is necessary to restore public trust and address fear sparked by images of masked agents carrying out immigration enforcement. The push followed a recent U.S. Supreme Court ruling that allowed the federal administration to resume broad immigration operations in Los Angeles, a decision proponents cited as making the measure more urgent.

"How is anyone supposed to reasonably believe that they are law enforcement officers and not masked individuals trying to kidnap you?" Assemblymember Juan Carrillo, vice chair of the Latino caucus, said before the vote. He argued the operations risk stopping people ‘‘based solely on their race, language, or job,’’ and said masks compound community fear.

Constitutional law experts and state officials offered differing views on whether California could compel compliance by federal agents. UC Berkeley law dean Erwin Chemerinsky wrote in an opinion piece that while states cannot directly regulate the federal government, federal employees generally must follow state rules unless doing so would significantly interfere with their duties — noting, for example, that federal employees are required to stop at red lights.

Republican lawmakers and several law enforcement groups warned the ban would endanger officers and hinder operations. "Bad guys wear masks because they don't want to get caught. Good guys wear masks because they don't want to get killed," state Sen. Kelly Seyarto, a Republican, said on the Assembly floor.

The debate reflects a broader clash over immigration enforcement tactics. The Trump administration has defended the use of masks by Immigration and Customs Enforcement and other federal agents, saying personnel and their families have faced increasing harassment and threats that make anonymity necessary for safety. State officials and some Democratic leaders counter that the public display of masked agents heightens fear and undermines trust in law enforcement.

California is the first state legislature to approve such a ban, but lawmakers in several other states including Tennessee, Michigan, Illinois, New York, Massachusetts and Pennsylvania have introduced similar proposals. State attorneys general and other officials have also criticized the federal tactics used in recent enforcement actions.

Legal and practical hurdles remain if Gov. Newsom signs the bill. Even supporters acknowledge uncertainty about the state's ability to enforce the rule against federal officers, and legal challenges are likely if the law is enacted. The bill's proponents say it could at minimum limit masking by state and local officers and set a policy standard governing agencies that cooperate with federal counterparts.

If the measure becomes law, its implementation and potential litigation could shape the extent to which state-level policy can influence the conduct of federal immigration operations. Newsom's office said it does not typically comment on pending legislation. The governor has previously criticized the use of masks in federal arrests while also questioning the state’s authority over federal agents.