Virginia Lt. Governor Ralph Northam was projected to defeat a progressive challenger for the Democratic nomination in the commonwealth's closely-watched race for governor, while former Republican National Committee chairman Ed Gillespie was projected to win a closer-than-expected GOP primary.
With 99 percent of precincts reporting, Northam led former U.S. Rep. Tom Perriello 56 percent to 44 percent. Perriello had run as an unapologetic liberal crusader supported by prominent national Democrats like Sens. Bernie Sanders and Elizabeth Warren as the best candidate to take on President Donald Trump.
With 99 percent of precincts reporting on the GOP side, Gillespie led former Trump state campaign chairman Corey Stewart by just over 4,000 votes out of nearly 365,000 ballots cast. State Sen. Frank Wagner was on course to finish a distant third.
The close Republican result shocked many political watchers and shows Trump's enduring appeal among Republican voters in Virginia, as well as a potentially rocky path forward for Republicans in a state where Democrats have won every statewide election since 2009.
Stewart had made his devout support for Trump a focus of his campaign, while Gillespie had distanced himself from the president and his policies. The former RNC head was backed by most of the state party establishment, and had the fundraising advantage.
Stewart, chairman of the Prince William County Board of Supervisors, has spoken out against moves to remove Confederate monuments from city streets and has advocated deporting all illegal immigrants upon arrest.
Virginia is one of only two states electing new governors this year (New Jersey is the other), and the swing-state contest is likely to draw intense national scrutiny for signs of how voters are reacting to Trump's first year in office.
Northam, a low-key pediatric neurologist, won running as a pragmatist with state's Democratic establishment's firm support. He gave a fiery victory speech Tuesday, vowing to win over Perriello supporters and lead Democrats in retaking control of the state House of Delegates in the general election.
"It is time for us to get back on offense and stop playing so much defense," Northam said.
At Northam's event in Arlington, there were cheers and high fives as news spread that he had been declared the victor.
A television over the bar displayed election returns and people examined their phones for breaking news.
Hyun Lee, 37, of Centreville, Va., who had done phone banking and knocked on doors for Northam, was one of the people at the party.
"I trust his leadership. I trust his dedication to all Virginians," Lee said of Northam. "He cares for everyone."
She said Northam has "proven he can work across the aisle."
Perriello made a surprise entrance into the race in January and faced an uphill climb from the beginning. He energized many new-to-politics voters who oppose Trump but was ultimately unable to expand the universe of Democratic primary voters enough to counter Northam's advantages.
Perriello pledged in his concession speech to help Northam and said his campaign had shown that a "movement" is "rising up."
"I don't know about you, but I'm inspired to keep fighting tonight," Perriello said.
Northam had been essentially campaigning for years, making key contacts with influential power brokers like prominent African-American politicians and religious leaders, and building up a large cash advantage that let him outspend Perriello on TV advertising in the closing weeks of the race.
Northam's campaign ran a more traditional campaign focused heavily on his biography -- rural upbringing, Army veteran, pediatric neurologist -- as well as his endorsements from key progressive groups that make up the Democratic base like teachers and abortion-rights groups.
Kevin Felty, a Norfolk Republican, said he voted for Gillespie because of his fundraising prowess in what's likely to be a bloody general campaign. Felty, a 48-year-old surgical assistant, said a GOP victory in Virginia would wrestle back the "narrative being touted in the mainstream media that the Democrats are gaining traction" under Trump.
"I see this as the midterm of the midterms," said Felty, who voted for Trump and remains steadfast in his support. "I think it has bigger consequences than people imagine."
At his victory party, Gillespie joked that he'd been fiscally prudent by not spending any more than was necessary to win the primary and asked the supporters of Stewart and Wagner to get behind him.
"We want you to be part of our effort," Gillespie said, adding that Virginia cannot afford another four years with a Democrat as governor.
But it's unclear how much Stewart supporters will rally behind Gillespie. Stewart repeatedly blasted the former Washington lobbyist as a product of the "swamp" Trump had pledged to drain, and said Tuesday evening that he's against party unity for unity's sake.
"There's one word you will never hear from me and that's `unity.' Because look, folks, we've been backing down too long ... in defense of our culture, our heritage and our country," said Stewart, who did not immediately concede.
Isaac Smith, 21, of Charlottesville, who campaigned for Stewart, said Stewart's showing was "remarkable" given the fact that he was badly outspent. Smith viewed the results as a vindication of Trump.
Asked if he would support Gillespie in the general election, Smith said: "At most, I will vote for him. I will not campaign for him."
The Associated Press contributed to this report.