With almost all votes counted, Gillespie was leading Stewart by about 1.2 percentage points, 43.7 percent to 42.5 percent, which is just outside the margin for a recount in the state. State Sen. Frank Wagner was on course to finish a distant third.
Northam wound up handily defeating former United States congressman Tom Perriello, a more liberal insurgent challenger supported by prominent national Democrats such as senators Bernie Sanders and Elizabeth Warren as the best candidate to take on Trump.
A victory for Northam would be an affirmation of the power of Democratic establishment that's backed him, including Sens.
But many Democrats voted pragmatically, wanting to choose someone with the most time in state government.
He and his supporters claimed a moral victory in the loss, saying they forced Mr. Northam to run to the left.
You all said that someone who supported our president, somebody who supported President Trump ... somebody who was out financed five-to-one ... somebody who was fighting against the establishment could never win!
Even before the primary, the Virginia election emerged as a swing-state referendum on Trump, who was defeated here by Hillary Clinton last November by 5 percentage points and remains deeply unpopular.
"It is time for us to get back on offense and stop playing so many defenses", he said, the AP reported. But the Associated Press called the Democratic race for Northam at 8:06 PM, while counting in the GOP lasted another two hours.
Gillespie - former Republican National Committee chairman, political consultant and 2014 U.S. Senate candidate running on an economy-focused message and calls to cut taxes - edged firebrand Corey Stewart, who modeled himself after President Donald Trump. Tim Kaine (D-Va.). He also saw endorsements from every Democrat in the state legislature and three of Virginia's four Democratic members of Congress. NARAL Pro-Choice America, the National Education Association teachers' union, and several gun control advocacy groups endorsed Northam.
Norfolk resident Andrew Patton was one voter drawn to Stewart, who briefly served as Trump's campaign chairman in Virginia before he was sacked from the post.
Democratic candidate for governor, Lt. Gov. Ralph Northam greets voters at a canvas kickoff Tuesday, June 13, 2017, in Chesterfield, Va. Lt. Gov Ralph Northam faces former Congressman Tom Perriello in today's primary.
In the primary for lieutenant governor, a post that often serves as a steppingstone to the governorship, Democrats chose Northern Virginia lawyer Justin Fairfax over retired prosecutor Gene Rossi and former lobbyist Susan Platt.
"We're going to see this play out all across the nation", John Weaver, an anti-Trump Republican strategist who works with Ohio Gov. John Kasich, told BuzzFeed News in an email.
Gillespie's GOP ticket-mate will be State Senator Jill Holtzman Vogel of Fauquier County. A Vogel victory would also end Virginia's more than two-decade streak without a woman in statewide elected office. "I think it has bigger consequences than people imagine".
He came very close to winning in Tuesday's primary election.
That lack of enthusiasm may have affected turnout.
But Gillespie, apparently trying to conserve resources and cement his frontrunner status, had avoided appearances with his campaign rivals in recent weeks, preferring smaller, more controlled settings. But there is a catch: You can only vote in one primary, either the Democratic primary or the Republican primary.
The Virginia gubernatorial primary on Tuesday delivered good news for Democrats and an ominous warning for the Trump-ized GOP.