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 N. 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.

But in a decision filed on Friday, Judge Bellis repeatedly cited the law, the Protection of Lawful Commerce in Arms Act, as the basis for her reasoning. “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, Conn., had argued for dismissal of the lawsuit. The complaint also named the wholesaler and a local retailer as defendants.