In a 54-page ruling, Judge Skretny struck down a well-known but troubled portion of the law, which prohibited gun owners from loading more than seven rounds into a magazine. He called the limit “an arbitrary restriction” that violated the Second Amendment.

But, saying that “whether regulating firearms is wise or warranted is not a judicial question; it is a political one,” he found that Mr. Cuomo and lawmakers had acted within their bounds when they drafted the gun laws, and specifically cited the Bushmaster rifle and 30-round magazine used in the Newtown shooting.

“Of course, this is only one incident,” Judge Skretny wrote. “But it is nonetheless illustrative. Studies and data support New York’s view that assault weapons are often used to devastating effect in mass shootings.”

He said that the gun law “applies only to a subset of firearms with characteristics New York State has determined to be particularly dangerous and unnecessary for self-defense; it does not totally disarm New York’s citizens; and it does not meaningfully jeopardize their right to self-defense.”

Even after the Newtown shooting, states passed more legislation in the last year loosening gun laws than tightening them. But gun control advocates, who celebrated the New York measure as a leading success story, said the ruling confirmed their position that the government had the right to pass strict controls on firearms.