RICHMOND — The Virginia Supreme Court has upheld Gov. Ralph Northam's temporary ban on guns in Capitol Square, which went into effect Friday at 5 p.m. and will continue through a major gun rights rally scheduled for Monday.

Concern about the rally, which organizers warn could attract tens of thousands of armed protesters, escalated in Richmond on Friday when President Trump drew attention to it on Twitter.

“Your 2nd Amendment is under very serious attack in the Great Commonwealth of Virginia,” Trump tweeted. “That’s what happens when you vote for Democrats, they will take your guns away. Republicans will win Virginia in 2020. Thank you Dems!”

Northam (D) announced the ban Wednesday as part of declaring a state of emergency, citing “credible intelligence” that some groups had threatened violent demonstrations against gun-control laws being considered by the legislature.

On Thursday, the FBI arrested three alleged members of a white-supremacist group on gun charges, partly out of concern that they planned to attend the Richmond rally and incite violence.

Two gun advocacy groups had filed suit to challenge the ban, arguing that it violated constitutional rights to free speech and to bear arms, as well as a state law restricting the governor’s power to ban guns during an emergency.

A Richmond Circuit Court judge upheld the ban Thursday, ruling that the governor was within his authority to protect public safety on the grounds around the Capitol. Lawyers for the Virginia Citizens Defense League and the Gun Owners of America immediately appealed Circuit Judge Joi Jeter Taylor’s ruling to the state Supreme Court.

If the ban were enforced, the lawyers said in their appeal, thousands of citizens would be “wrongfully and unlawfully denied entry to the grounds of the Virginia State Capitol merely because they are exercising their preexisting rights.”

They also noted that a law passed by the General Assembly in 2012 specifically forbids the governor from using a declaration of emergency to ban guns, except within emergency shelters. Both Northam and state Attorney General Mark R. Herring (D), they pointed out, were state senators at the time and voted in favor of the policy.

Lawyers in Herring’s office said they worked through the night to write a response to the appeal. They also requested permission to file a longer brief “because the haste with which the plaintiffs are proceeding means this is the first and likely only opportunity for the Commonwealth to file a brief on this matter,” according to a statement from Herring’s office.

The state invoked the violent Unite the Right rally in 2017 in Charlottesville, in which armed militias clashed with counterprotesters. One woman, Heather Heyer, was killed when a white supremacist drove his car into a crowd, and two state police officers died when their helicopter crashed nearby.

“Determined to prevent another tragedy, the Governor issued a carefully limited Executive Order,” the state lawyers argued. “The Order does not prevent anyone from speaking, assembling, or petitioning the government. Instead, it temporarily precludes private possession of firearms in a sensitive public place during a specified time to protect public safety.”

In refusing to overturn the ban, the Supreme Court faulted the pro-gun lawyers for failing to include enough information to merit taking action. They noted that the lawyers had alternately referred to what they sought as a “temporary injunction” and a “preliminary injunction” and that there was no transcript provided of the hasty hearing held in Circuit Court the day before.

“The only information we have on which to resolve the weighty issues raised by the parties are pleadings accompanied by cursory attachments. Accordingly, the petition is refused,” six of the court’s seven justices wrote.

Democrats won control of both chambers of the General Assembly in elections last fall, partly based on campaign promises to enact gun-control measures. The issue took on urgency after a gunman killed 12 people in a Virginia Beach municipal complex in May.

The state Senate passed three gun-control bills 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.

A Democratic-controlled rules committee last week imposed a permanent ban on carrying guns inside the Capitol and a legislative office building; this week’s court cases did not challenge that measure.

The prospect of Democratic action, after 26 years of Republican control 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 threats of violent insurrection and civil war.

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

Northam’s office planned to brief Republican and Democratic leaders Friday afternoon on the law enforcement intelligence that went into the declaration of emergency.

Capitol and state police have had a major presence at this year’s General Assembly session, and they have installed metal barricades and other security measures around the Capitol grounds in preparation for Monday’s rally.