Virginia's state Senate passed a bill that would allow law enforcement officers to confiscate guns from or prevent the purchase of firearms by people deemed to be threats to themselves or others, just days after a massive gun rights rally swarmed the state Capitol.

The bill passed the chamber in a narrow 21-19 vote and will next move to the state House of Delegates.

Jake Rubenstein, a spokesman for Virginia House Speaker Eileen Filler-Corn (D), told CNN the House would "deliver" on a demand from voters for gun control measures.

"Virginians spoke loud and clear on Election Day demanding common sense gun violence protections, and make no mistake, we will deliver on that mandate," Rubenstein said.

If passed, the bill would allow state attorneys or law enforcement officers to apply for a judge's order to "prohibit a person who poses a substantial risk of injury to himself or others from purchasing, possessing, or transporting a firearm."

The bill is expected to be signed into law by Virginia Gov. Ralph Northam (D), who has indicated support for stronger gun control measures, should it pass the House of Delegates later this session.

Thousands of gun rights activists poured into Richmond on Monday for a massive rally against further gun control measures by the Democratic-controlled state legislature, with many toting assault-style weapons and tactical gear.

The rally ended peacefully after several hours, with one woman being arrested for violating a statute banning masks in public.