A judge upheld Seattle's so-called gun violence tax Tuesday, rejecting a challenge from the National Rifle Association and other gun rights groups.

King County Superior Court Judge Palmer Robinson dismissed arguments that Seattle's tax, adopted last summer, exceeded the city's authority under state law.

The measure — one of only a couple of its kind in the nation — adds $25 to the price of each firearm sold in the city, plus 2 or 5 cents per round of ammunition, depending on the type. Officials expect it to raise up to $500,000 a year to help offset the costs of gun violence. The measure is set to take effect next month.

"The NRA and its allies always oppose these commonsense steps to shine light on the gun violence epidemic," said City Council President Tim Burgess, who sponsored the law. "Judge Robinson saw through the NRA's distorted efforts to put gun industry profits ahead of public safety."

The NRA did not immediately respond to a call seeking comment, but another plaintiff, the Bellevue-based Second Amendment Foundation, promised an immediate appeal. The groups have argued state law puts responsibility for regulating firearms solely in the hands of the Legislature, not local governments.

"It is unconscionable for Mayor Ed Murray and the City Council to codify what amounts to social bigotry against firearms retailers and their customers," Second Amendment Foundation founder Alan Gottlieb said in a written statement.

But the judge found the measure falls within the city's taxing authority and is not an impermissible regulation.

The City Council modeled the tax after a similar one in Cook County, Illinois, which includes Chicago; the NRA has said Chicago is the only other city with such a measure. The revenue would be used for gun safety research and gun violence prevention programs.

Between 2006 and 2010, there were on average 131 firearms deaths a year in King County, according to Public Health-Seattle and King County. An additional 536 people required hospitalization for shooting injuries during that time.

Officials say the direct medical costs of treating 253 gunshot victims at Harborview Medical Center in 2014 totaled more than $17 million. Taxpayers paid more than $12 million of that. City officials estimate the new tax would bring in $300,000 to $500,000 a year, but gun shop owners told council members those numbers were inflated. They said the law would cost them customers and sales and could force them to move out of the city.

"Guns now kill more people in the United States than automobiles," Seattle's mayor said. "Our community will not stand by as so many in our city, particularly young people of color, continue to pay the highest price for inaction on gun violence at the national and state level."