SACRAMENTO, Calif. — High-capacity gun magazines will remain legal in California under a ruling Friday by a federal judge who cited home invasions where a woman used the extra bullets in her weapon to kill an attacker while in two other cases women without additional ammunition ran out of bullets.

“Individual liberty and freedom are not outmoded concepts,” San Diego-based U.S. District Judge Roger Benitez wrote as he declared unconstitutional the law that would have banned possessing any magazines holding more than 10 bullets.

California law has prohibited buying or selling such magazines since 2000, but those who had them before then were allowed to keep them.

In 2016, the Legislature and voters approved a law removing that provision. The California arm of the National Rifle Association sued and Benitez sided with the group’s argument that banning the magazines infringes on the Second Amendment right to bear arms.

Benitez had temporarily blocked the law from taking effect with a 2017 ruling.

Attorney General Xavier Becerra said in a statement that his office is “committed to defending California’s common sense gun laws” and is reviewing the decision and evaluating its next steps.

Chuck Michel, an attorney for the NRA and the California Rifle & Pistol Association, praised what he called a “well-researched and comprehensive ruling.”

The decision “recognizes that the Second Amendment is not a second-class right and that the state has to meet a high burden before it can pass a law that infringes on the right to keep or bear arms,” Michel said.

There have been conflicting decisions on extended magazines by judges in different states and the issue may ultimately be sorted out by the U.S. Supreme Court.

Benitez described three home invasions, two of which ended with the female victims running out of bullets.

In the third case, the pajama-clad woman with a high-capacity magazine took on three armed intruders, firing at them while simultaneously calling for help on her phone.

“She had no place to carry an extra magazine and no way to reload because her left hand held the phone with which she was still trying to call 911,” the judge wrote, saying she killed one attacker while two escaped.

He ruled that magazines holding more than 10 rounds are “arms” under the U.S. Constitution, and that the California law “burdens the core of the Second Amendment by criminalizing the acquisition and possession of these magazines that are commonly held by law-abiding citizens for defense of self, home, and state.”