Gun manufacturers must do their best to comply with a California law requiring new models of semiautomatic handguns to imprint their bullets with identifying micro stamps so police can trace them, the state Supreme Court ruled Thursday, rejecting the companies’ arguments that the law should be overturned because compliance is technologically impossible.

A gun-control advocate said the ruling preserves safety regulations that encourage industries to develop new technologies. A gun organization’s lawyer said the state is headed for a “slow-motion handgun ban.”

The gun law, passed in 2007, is supported by police organizations that say the stamps would help officers to determine the source of bullets found at crime scenes. It requires that new brands of semiautomatic pistols introduced for retail sale in California carry markings in two places that would imprint the gun’s model and serial number on each cartridge as it is fired.

The law didn’t take effect until 2013, when the state certified that there were no patent restrictions on the technology. But gun manufacturers have not sold any new models of semiautomatic handguns in California since then, and in 2014 a gun group sued to invalidate the law, saying its standards could never be met.

A state appellate court allowed the suit to proceed, relying on an 1872 California statute that declared, “The law never requires impossibilities.” On Thursday, however, the state’s high court dismissed the suit and said the law would remain on the books, even if it was difficult to enforce.

“Impossibility can occasionally excuse noncompliance with a statute,” Justice Goodwin Liu said, since a manufacturer charged with violating the law could argue that it had done everything possible to comply. “But impossibility does not authorize a court to go beyond interpreting a statute and simply invalidate it.”

Five fellow justices signed Liu’s opinion. Justice Ming Chin wrote a separate opinion agreeing that the law should remain on the books but saying the court should have made it clearer that manufacturers currently had a valid defense if they were charged with violating the law.

The ruling effectively ends the case, but other gun organizations have sued in federal court, claiming the law is unconstitutional. Their case is pending before the Ninth U.S. Circuit Court of Appeals and could ultimately reach the U.S. Supreme Court.

For now, no new models of semiautomatic handguns will be marketed in California, said Larry Keane, general counsel for the National Shooting Sports Foundation, which challenged the law in state court. He said the number of handgun models sold in California has dropped by about 50 percent since the state certified the micro-stamping law in 2013.

“California will experience a slow-motion handgun ban,” Keane said. He said sales would “never go up because no new model can meet the impossible requirement.”

Gun makers acknowledge micro stamping is feasible, but say it can’t possibly be done in two separate places in a handgun’s chamber. But the Giffords Law Center to Prevent Gun Violence, which filed arguments in support of the law, said dual stamping has been tested and certified, with the inventor submitting a declaration to that effect during current legal proceedings.

“They’ve chosen to engage in obstructionism rather than implement the technology,” Hannah Shearer, a lawyer for the organization, said Thursday.

She said the ruling also allows the state to keep enacting safety laws on a wide variety of products that require manufacturers to upgrade their technology, such as new motor vehicle emissions standards.

“This has broader implications for California’s regulations in other important areas, like environmental regulation and product safety,” Shearer said.

Attorney General Xavier Becerra, whose office defended the state law, said the ruling “confirms that California can create incentives for the gun industry to make products that serve the public’s needs.”

The case is National Shooting Sports Foundation vs. California, No. S239397.

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