By Denise Lavoie, AP

Virginia’s highest court on Friday upheld a ban on firearms at a pro-gun rally in the state’s capital next week, an event that authorities feared could erupt in violence at the hands of armed extremists.

Gov. Ralph Northam earlier this week declared a state of emergency and issued an executive order banning all weapons from the Capitol grounds in Richmond, saying the state had received credible threats of “armed militia groups storming our Capitol” during an annual gun-rights rally scheduled for Monday.

Shorter SCOVA: We don’t know enough about what’s going on to even deal with this pic.twitter.com/Ds1OAbUMyx — Graham Moomaw (@gmoomaw) January 17, 2020

Gun-rights groups sued, but a Richmond judge on Thursday denied their request to lift the ban, citing rulings from the U.S. Supreme Court and other courts that the Second Amendment right to bear arms is not unlimited. On Friday, the state Supreme Court agreed and upheld the ban.

Gun-control proposals gained momentum in Virginia after a city employee opened fire on co-workers at a municipal building in Virginia Beach in May, killing 12 people and injuring four others.

After Democrats who promised to pass a slew of new gun restrictions won a majority in Virginia’s state legislature in November, gun-rights groups began a fierce opposition campaign. More than 125 cities, towns and counties have declared themselves “Second Amendment Sanctuaries” and promised to fight new gun control laws.

The annual rally sponsored by the gun-rights group Virginia Citizens Defense League — scheduled for Monday, which is also Martin Luther King Jr. Day — has drawn attention from militia groups, white supremacists and anti-government groups who have promised to send members to Virginia to protest new gun laws.

Virginia Attorney General Mark Herring urged the state Supreme Court to uphold the weapons ban imposed by the governor, arguing it was necessary to prevent a repeat of deadly violence that erupted at a white nationalist rally in Charlottesville in 2017. One woman was killed and more than 30 others were hurt when a white supremacist drove his car into a crowd. No one was wounded by gunfire at the rally.

Gun-rights groups argued that the ban would violate their Second Amendment right to bear arms and their First Amendment freedom of speech.