Stewart, chairman of the Prince William County Board of Supervisors and former state chairman for Donald Trump's presidential campaign, has attempted to ride the Trump effect to the GOP nomination with his tough stands on immigration and protection of Confederate statues. Gillespie was expected to win easily, and the close contest shows Trump's enduring appeal among GOP voters in Virginia and a potentially rocky path forward for Republicans in a state where Democrats have won every statewide election since 2009.
Updated | The Virginia gubernatorial race is proving to be a fascinating proxy for national trends as an ally of Bernie Sanders and Elizabeth Warren was defeated on Tuesday, and a Trump-style nationalist came close to defeating the mainstream, better financed Republican front runner.
Unofficial results from the state Department of Elections in the Democratic primary, with 99.9 percent of districts reporting, were Northam, 303,051 (55.9 percent); Perriello, 239,028 (44.1 percent).
Virginia is one of two states electing governors this year, and the race is testing the enthusiasm of the electorate in both parties in the wake of Trump's victory.
"It is really the first big test in a statewide election of the state of the Democratic Party in the Trump era", said Mark Rozell, dean of the Schar School of Policy and Government at George Mason University.
"This fight will continue, and I'll continue to fight as long as you'll fight with me", Stewart told a roaring crowd of several dozen supporters.
Protestors take over the stage prior to Virginia Democratic candidate for governor, Lt. Gov. Ralph Northam celebrating his primary win at a Democratic primary election party in Crystal City, Va., Tuesday, June 13, 2017.
Former Virginia Republican chairman Shaun Kenney said Stewart chose high-level negativity to "drive down turnout to the fanatical base and lean on that base to turn out".
Virginia voters cast their ballots in the Democratic primary Tuesday, choosing their candidates for the gubernatorial, lieutenant gubernatorial and House of Delegates races.
Perriello had the backing - but not the explicit endorsement - of President Barack Obama, who taped a campaign ad for him.
Northam, a usually low-key pediatric neurologist, won running as a pragmatist with state's Democratic establishment's firm support.
"Virginia is going to be the match that sparks a progressive wildfire that spreads across the country".
Gillespie likely will begin the race with significantly more money than Northam, who will need to refill his campaign chest after flooding the airwaves with commercials to fend off Perriello.
Democrats have seen a surge in candidates for the House of Delegates this year, where they have a longshot at taking back control of the chamber from Republicans in November. But like Perriello, Northam has been unsparing in criticism of Trump, calling him a "narcissistic maniac".
The Democrats have made elections in Virginia and Georgia a referendum on President Trump. Jill Vogel eked out a narrow win over state Sen.
On the Democratic side, attorney Justin Fairfax beat Gene Rossi, a retired federal prosecutor, and Susan Platt, a longtime political operative and former lobbyist.
Gillespie is backed by most of the state party establishment and has focused on pocketbook issues, including proposing a modest cut to the state's income tax rate.
It is unclear if the defeat of Stewart or the narrowness of that defeat - when it was expected to be by a much larger margin - is a show of support for the president or a statement against him.