A Connecticut judge has dismissed a lawsuit filed by relatives of victims of the Sandy Hook Elementary School attack, delivering a blow to an ambitious effort to hold accountable the makers of the assault rifle used in the 2012 massacre before the case ever went to trial.

The judge, Barbara Bellis of state Superior Court, had surprised even some of the plaintiffs by allowing the case to move toward trial this year, despite a 2005 federal law that offers firearm manufacturers and sellers broad protection from lawsuits when guns are used in crimes.

“This action falls squarely within the broad immunity provided” by the act, she wrote.

Lawyers for Remington Outdoor, whose AR-15-style Bushmaster rifle was used by Adam Lanza in the attack at the school, in Newtown, Connecticut, had argued for the dismissal. The complaint also named the wholesaler and a local retailer as defendants.

Lawyers for the plaintiffs, who include relatives of nine of the 26 people who were killed in the shooting, as well as a teacher who survived, contended that the law’s exception for cases of negligent entrustment, in which a gun is carelessly given or sold to a person posing a high risk of misusing it, justified the complaint.

They argued that the manufacturers and distributors of assault rifles modeled on the AR-15 had been negligent in selling the weapons to civilians, who are not trained to handle a gun that is “designed to be used in combat to assault and kill enemies of war,” as Joshua Koskoff, one of the families’ lawyers, said in June.

Bellis ruled that their claims were too broad to fall under negligent entrustment and said Congress had already deemed the civilian population competent to possess the weapons by the nature of its law.

James Vogts, a lawyer for Remington, said the company was “very pleased with the court’s decision.”