A federal judge has upheld California’s ban on owning, manufacturing or selling semiautomatic rifles and the “bullet buttons” that convert a conventional rifle into a rapid-fire weapon.

Semiautomatic rifles are “incredibly effective killing machines” that are not commonly used or necessary for self-defense, said U.S. District Judge Josephine Staton of Santa Ana. She rejected a challenge to the law by the California Rifle & Pistol Association, an arm of the National Rifle Association.

Her ruling Monday was the first federal court decision on the California law, and cited federal court rulings that have upheld similar laws in other states. It contrasted sharply with decisions in 2017 and 2018 by a federal judge in San Diego, who said the state’s ban on high-capacity gun magazines — those holding more than 10 cartridges — violated the right of law-abiding citizens to defend themselves.

U.S. District Judge Roger Benitez’s rulings took effect briefly this spring, prompting what firearms advocates described as a flurry of purchases at gun shops around the state, but Benitez agreed to restore enforcement of the law after the state appealed. The case is awaiting review by the Ninth U.S. Circuit Court of Appeals.

Semiautomatic rifles, classified as “assault weapons” under state law, have detachable magazines and pistol grips or other features that allow repeated firing without frequently reloading. California has banned the weapons for 20 years, and in 2016 also outlawed “bullet buttons,” which are attached to regular gun magazines and allow them to be quickly removed and replaced.

The rifles were banned nationwide by a federal law that was passed in 1994 but expired in 2004 when Congress refused to renew it. Sen. Dianne Feinstein, D-Calif., sponsored the law after a gunman killed eight people at a San Francisco law office in 1993, and has introduced multiple measures to revive the ban..

In its lawsuit, the NRA affiliate, joined by individuals who said they wanted to purchase the weapons, cited a 2011 opinion by Brett Kavanaugh, then a federal appeals court judge in Washington, D.C., and since October a Supreme Court justice.

In that opinion, Kavanaugh dissented from a ruling that upheld gun regulations in the nation’s capital. Instead, he argued that the Second Amendment should be interpreted to allow possession of semiautomatic weapons and prohibit mandatory gun-registration laws.

Gun groups are hoping that the addition of Kavanaugh and President Trump’s other appointee, Justice Neil Gorsuch, will increase their support on the Supreme Court, which has agreed to consider whether the Constitution guarantees the right to carry firearms outside the home.

But Staton said that under current standards set by the Supreme Court and the Ninth U.S.Circuit Court of Appeals, a semiautomatic rifle should be considered a “dangerous and unusual weapon” that is suitable for military service but not for self-defense in the home. That means it is not covered by the Second Amendment’s right to bear arms, she said.

The judge cited congressional findings that semiautomatic rifles have a rate of fire, 300 to 500 rounds per minute, that makes them “virtually undistinguishable”from machine guns, and that they are the “weapons of choice” for gangs, hate groups, and “mentally deranged persons bent on mass murder.” She said the state also presented evidence that semiautomatics fire bullets that can pass through both humans and buildings and therefore pose a greater risk of striking innocent bystanders.

The ruling is “the latest confirmation from the courts that there is no conflict between reasonable gun safety laws and the Second Amendment,” said attorney Eric Tirschwell of Everytown for Gun Safety, which filed arguments supporting the law.

The gun advocates’ lawyers could not be reached for comment. They can appeal the ruling to the Ninth Circuit.

Bob Egelko is a San Francisco Chronicle staff writer. Email: begelko@sfchronicle.com Twitter:@BobEgelko