California will become the first state to allow family members to ask a judge to temporarily seize guns from someone who is suspected of posing an immediate danger.

Under the legislation, signed Tuesday by California’s Democratic Gov. Jerry Brown, family members or law-enforcement officers can petition to remove firearms from an individual.

Authorities in Connecticut, Indiana and Texas can ask a judge to let them seize guns from people they deem to be dangerous. The California law extends the provision to relatives. The law is effective Jan. 1.

The legislation was introduced after the deadly rampage in Isla Vista, Calif., in May in which 22-year-old Elliot Rodger shot and stabbed six people to death around the campus of the University of California, Santa Barbara.

State Assemblywoman Nancy Skinner, a Democrat who sponsored the bill, said in an interview the law would help prevent similar situations. Mr. Rodger’s mother, after seeing disturbing videos her son posted online, alerted his therapist, who in turn alerted authorities with concerns about the young man. Police visited him, but determined he wasn’t a danger. Mr. Rodger was in the middle of planning his deadly attack at the time of their visit. A few weeks afterward, he went on his rampage, and then apparently killed himself.

“What this bill does is provide an effective and needed tool that she could’ve used or law enforcement could’ve used to remove weapons from Elliot or others who are threatening to commit acts of violence,” Ms. Skinner said.

Under the law, judges can grant restraining orders that prevent these individuals from temporarily possessing or buying guns.

A full version of this story is available on wsj.com