Corey Stewart, the populist former Trump campaign state chairman who ran on an unrestrained Trumpian populist platform, stands only 1.15 percent back from Gillespie, who most mainstream outlets reported would coast to victory. Gillespie barely defeated Corey Stewart, who was sacked as Trump's state campaign chairman a year ago and focused his gubernatorial bid on preserving Virginia's Confederate history.
Sen. Jill Vogel (R-27th) edged out opponents Bryce Reeves and Glenn Davis Jr. for the Republican lieutenant governor nomination with 42.3 percent of the vote.
On Tuesday, voters in Virginia will select the Republican and Democratic Party candidates for the governor election in November.
Northam easily defeated former U.S. Rep. Tom Perriello in the more closely watched Democratic contest by almost 12 points, which pitted the progressive Perriello against the establishment Northam. The dichotomy evoked comparisons to the 2016 Democratic presidential primary contest between the upstart Sanders and the establishment Hillary Clinton.
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.
The initial strategy helped Perriello pull even, and by early May, Northam was running ads in which he called Trump a "narcissistic maniac".
Stewart also gained attention during the primary campaign for his defense of Confederate monuments.
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.
Obama never joined Perriello on the campaign trail, as he did in 2010 when the congressman was fighting an ill-fated battle to keep his seat in the House.
"I think if someone looks at my history of public service in Virginia, they will see that I have been unwavering in support of progressive Democratic values", Northam argued. He beat challengers, Ed Gillespie and Frank Wager.
Fairfax County saw a 13.4 percent voter turnout for the Democratic primary.
In Floyd County, where Republicans have long dominated local politics, Stewart's message of stauch protection of icons of the loss in America's Civil War more than a century and a half ago, along with hateful rhetoric about immigrants and race, gave the Prince William County supervisor a big win over Gillespie and leaves local Republicans worries about their own political futures down the pike.
"He is experienced", Sandra Welch, 71, said of Mr. Northam as she voted in Alexandria.
Gillespie polled below both Democratic challenge unanimously in the May polls, earning only 38 percent compared to Northam's 49 percent, and 37 percent compared to Perriello's 50 percent in the latest WaPo poll.
His race for governor is too close to call, he said. Smith viewed the results as a vindication of Trump.
Democratic Governors Association Chairman Dan Malloy of CT, meanwhile, said in a statment that Northam would "continue Governor McAuliffe's work of growing the economy, fighting for the middle class and protecting Virginians' health care". Roem has sharply criticized Marshall's support for his North Carolina-style "bathroom bill", saying that "Bob Marshall is more concerned about where I use the bathroom than how to get people to work".