By Sharon Bernstein

SACRAMENTO Calif. (Reuters) - People who fear a close relative may commit gun violence will be able to petition a judge to temporarily remove the person's firearms in California, under a bill signed into law on Tuesday by Democratic Governor Jerry Brown.

The legislation - the first such measure in the United States - was introduced after police near Santa Barbara said they were unable to confiscate weapons from a man who later went on a rampage and killed six people, despite concern from his family he was in poor mental health and might become violent.

Under the so-called gun violence restraining order in the court system, immediate family members and law enforcement agencies could ask a judge to order guns temporarily removed from certain individuals.

The restraining order would last 21 days, and could be extended up to a year, after a notice and a hearing.

“The new ‘Gun Violence Restraining Order’ law will give families and law enforcement a needed tool to reduce the risk of mass shootings and gun violence both in the home and on our streets,” said Nick and Amanda Wilcox, legislative co-chairs of the California Chapters of the Brady Campaign to Prevent Gun Violence.

The law has wide support from law enforcement agencies and is based on an existing measure that temporarily blocks people with domestic violence restraining orders from owning a gun.

"If it can save one life, one family from that agony, it will be worth it," Democratic state Senator Hannah-Beth Jackson, said during debate on the measure.

Several Republican senators spoke against the bill, saying there were already measures in place to keep guns away from dangerous and unstable people.

Critics added that the bill infringed on the Second Amendment right to keep and bear arms.

Brown also signed a bill on Tuesday requiring BB guns and pellet guns to be brightly colored or otherwise marked so that law enforcement officers do not mistake them for deadly firearms.

The bill was introduced after a 13-year-old Northern California boy was shot and killed by a sheriff's deputy while carrying a pellet gun that looked like an assault weapon.

The law also expanded the definition of a BB gun in California to include firearms that shoot pellets larger than 6 millimeters.

(This story has been refiled to fixe typographical error in headline)

(Reporting by Sharon Bernstein; Editing by Peter Cooney)