RICHMOND — A Circuit Court judge upheld Gov. Ralph Northam's temporary ban on firearms in Capitol Square ahead of Monday's gun rights rally, which is expected to draw thousands of armed activists from across the country.

From Friday night until Tuesday, weapons of any kind will be prohibited on the grounds of the Capitol under a state of emergency. Northam (D) said the precaution was necessary because of “credible intelligence” that militias and gun rights advocates are threatening violence at the rally.

“This is the right decision,” Northam said in a statement about Richmond Chief Judge Joi Jeter Taylor’s ruling Thursday afternoon. “These threats are real — as evidenced by reports of neo-Nazis arrested this morning after discussing plans to head to Richmond with firearms.”

Gun rights groups filed an appeal to the Virginia Supreme Court on Thursday evening.

Earlier Thursday, the FBI arrested three alleged members of a white supremacist group on gun charges, in part out of concern over the potential for violence at the planned rally in Richmond. The three were to appear in court in Maryland.

Northam announced the gun ban Wednesday and it was quickly challenged in court by the Virginia Citizens Defense League (VCDL), the rally’s primary organizer, as well as Gun Owners of America.

Taylor held a whirlwind hearing Thursday afternoon and promised to rule quickly, to allow time for appeals.

Arguing for the pro-gun groups, lawyer David Browne told the judge that Northam’s order was “an unconstitutional restraint on rallygoers” that violated state law and infringed on protesters’ rights to arms, assembly and speech.

Taylor rejected that argument. “The Second Amendment right to bear arms is not unlimited,” the judge wrote, citing a federal case that upheld a ban on weapons on U.S. Postal Service property.

Philip Van Cleave, president of the VCDL, said after the ruling that his group intended to appeal to the Virginia Supreme Court. “Basically I didn’t hear anything in her ruling that made any sense in our case, so on to the next level,” he said.

A Democratic-controlled rules committee last week imposed a permanent ban on carrying guns inside the Capitol and a legislative office building; the court case heard Thursday did not challenge that ban.

Led by Northam, Democrats who gained majorities in both chambers of the General Assembly in last fall’s elections have pledged to enact a package of gun-control measures this year.

The Senate passed three gun-control bills on Thursday, sending them to the House for its consideration. They would require background checks on all firearms sales, cap handgun purchases at one per month, and let local governments ban weapons from government buildings, parks and certain events.

Two Republicans, Siobhan S. Dunnavant (Henrico) and Emmett W. Hanger Jr. (Augusta), joined Democrats to support the background check bill. The others passed on party lines, 21 to 19.

A proposed ban on assault weapons has stalled as some Democrats waver on particulars. A “red flag” law allowing authorities to temporarily seize weapons from someone deemed a threat was approved in a Senate committee but has not yet been taken up by the full chamber.

The prospect of Democratic action, after 26 years of Republican control had effectively blocked all gun restrictions, has stirred anger among gun advocates in Virginia and beyond.

In recent weeks, militias and extremist groups across the country have urged thousands of people to descend on Richmond on Monday to protest. Law enforcement officials say they’ve been monitoring threatening language on websites and social media, including promises of violent insurrection and civil war.

Organizers are trying to get more than 50,000 people to attend, and law enforcement authorities are taking that prospect seriously.

“To those who would come here intending to incite violence I simply say stay home. Don’t come to Virginia. Don’t come to Richmond,” state Attorney General Mark R. Herring (D), whose solicitor general had defended the ban, said Thursday in a statement.

Browne, the lawyer for the VCDL, told the judge Thursday that he did not dispute the governor’s decision to declare a state of emergency. “We understand why he did that in order to have additional resources to manage an event that’s expected to be very large,” Browne said.

But Browne cited a law passed by the General Assembly in 2012 that prohibits the governor from using an emergency declaration “to in any way limit or prohibit the rights of people to keep and bear arms.”

He insisted that the VCDL intends the rally to be peaceful but acknowledged that “I don’t think anybody can predict what is going to happen at an event that is several days away.”

Like Northam, Browne invoked the specter of the 2017 Unite the Right rally in Charlottesville, in which armed militias clashed with counterprotesters and one young woman was killed when a white supremacist ran his car into a crowd of people.

But Browne said Northam’s actions “ironically would increase the chances of another Charlottesville-type event,” by restricting armed attendees to the streets around Capitol Square, where they would be more likely to clash with opponents.

Virginia Solicitor General Toby Heytens said that Northam’s “targeted, limited” ban does not infringe constitutional rights; that protesters will be free to speak and hold signs; and that public safety is a paramount concern.

Taylor ruled that Northam has the authority to impose the ban as part of his duties to ensure safety around the Capitol. When a governor declares an emergency, she wrote, previous decisions established that “ ‘courts must give deference to the professional judgment’ of those tasked with making ‘complex, subtle, and professional decisions.’ ”

Laura Vozzella contributed to this report.