SACRAMENTO — Last year’s fatal shooting of 13-year-old Andy Lopez prompted state lawmakers Thursday to approve a bill requiring bright markings on air guns similar to the one the boy was carrying when he was shot and killed by a Sonoma County sheriff’s deputy.

Lopez was killed Oct. 22 as he walked along Moorland Avenue in an unincorporated part of Santa Rosa by Deputy Erick Gelhaus, who reportedly mistook the boy’s BB gun for a real AK-47. The shooting, as well as District Attorney Jill Ravitch’s decision not to file charges against Gelhaus, prompted weeks of protests through the streets of Santa Rosa and at city and county government buildings.

“Had this bill been law, I believe he would be alive today,” said Sen. Noreen Evans, D-Santa Rosa, a sponsor of the bill. “The bottom line is that a toy should look like a toy, and a toy should not get a child killed.”

SB199 would apply to guns that fire pellets or BBs that are six millimeters or eight millimeters. They would have to have brightly colored surfaces or prominent fluorescent strips.

The bill passed the Senate on a 22-12 party-line vote and goes to the governor. Republican lawmakers objected, saying criminals could simply paint real guns to confuse police.

“Criminals will be painting up all kinds of dangerous weapons,” said Sen. Jim Nielsen, R-Gerber. “It’s another way to disarm the law-abiding citizens. . . . Be aware of unintended consequences.”

Moreover, some real weapons are now manufactured in bright colors, said Sen. Joel Anderson, R-Alpine.

“Women like pink pistols. It appeals to their feminine side, I’ve been told,” Anderson said.

He and Republican Sen. Steve Knight of Palmdale, a former Los Angeles police officer, said painted guns would be enough to confuse police officers for crucial seconds while they decide whether to shoot.

The only real solution, said Anderson, is for parents to teach children, “Don’t wave a weapon at law enforcement, whether it’s real or unreal.”

Sen. Kevin de Leon, D-Los Angeles, noted that the bill is supported by several law enforcement officials.

De Leon unsuccessfully introduced a similar bill in 2011 after another 13-year old, Rohayent Gomez, was shot and left a paraplegic when Los Angeles police thought his replica firearm was a real weapon.

Gomez’s family won a $24 million jury verdict after suing the Los Angeles Police Department. Their attorney, Arnoldo Casillas, is representing the Lopez family in its wrongful death lawsuit against Gelhaus and Sonoma County.

Other bills acted on by the Legislature on Thursday included:

AB1609 by Assemblyman Luis Alejo, D-Watsonville, would make it illegal for gun buyers to purchase a gun from out-of-state sellers without going through a licensed dealer in California, extending a federal requirement to state law. The bill heads to the governor after passing the Assembly on a 48-24 vote.

AB913 by Assemblyman Ed Chau, D-Monterey Park, would require charter schools to abide by the same conflict-of-interest, open-meeting and transparency laws that public schools do. The bill heads to the governor after passing the Assembly on a 52-23 vote.

AB877 by Assemblymen Raul Bocanegra and Reggie Jones-Sawyer, Los Angeles Democrats, would prohibit sports franchise owners like Donald Sterling from writing off fines imposed by sports leagues as business expenses. It heads to the governor on a 54-12 Assembly vote, the minimum needed to increase taxes.

AB1672 by Assemblyman Chris Holden, D-Pasadena, would expand requirements for annual reports on student enrollment, absence and truancy rates. It passed the Assembly on a 55-17 vote. It is the last of four bills backed by Attorney General Kamala Harris to reduce truancy. All four are now on the governor’s desk.

AB2293 by Assemblywoman Susan Bonilla, D-Concord, would require drivers who provide ride sharing for companies such as Uber and Lyft to carry a minimum level of insurance and the companies to carry excess insurance. The Assembly passed the compromise legislation 67-0, sending it to the governor.

SB1441 by Sen. Richardo Lara, D-Bell Gardens, would ban fundraisers for state elected officials at lobbyists’ homes. The bill addresses recent campaign-finance violations involving a prominent capital lobbyist and numerous lawmakers. It passed the Senate, 37-0, and now goes to the governor.

SB846 and SB1066 by Sen. Cathleen Galgiani, D-Stockton, would clarify that law enforcement can check with the Department of Justice for links between unsolved missing person cases. Both bills passed the Senate 34-0 and go to the governor.