Republican candidate for governor, Ed Gillespie, arrives on stage with his wife Cathy as he prepares to deliver a victory speech at his victory party Tuesday, June 13, 2017, in Richmond, Va. Gillespie beat State Sen. Frank Wagner and Corey Stewart in today's primary. (AP Photo/Steve Helber)

Republican candidate for governor, Ed Gillespie, arrives on stage with his wife Cathy as he prepares to deliver a victory speech at his victory party Tuesday, June 13, 2017, in Richmond, Va. Gillespie beat State Sen. Frank Wagner and Corey Stewart in today's primary. (AP Photo/Steve Helber)

RICHMOND, Va. (AP) — Virginia Lt. Gov. Ralph Northam won the Democratic nomination in the closely watched race for governor Tuesday, defeating a more liberal insurgent challenger in a contest to be one of the party’s standard-bearers against President Donald Trump.

Northam will face Ed Gillespie in the general election. The former Republican National Committee chairman eked out an uncomfortably close victory against an outspoken Trump supporter who made preserving Virginia’s Confederate history a top campaign issue.

ADVERTISEMENT

Although the Democratic contest garnered the most pre-election attention, Gillespie’s narrow victory against former Trump state campaign chairman Corey Stewart provided the night’s biggest surprise. 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.

Northam wound up handily defeating former U.S. Rep. Tom Perriello, who ran as an unapologetic liberal crusader supported by prominent national Democrats like Sens. Bernie Sanders and Elizabeth Warren as the best candidate to take on Trump.

Northam, a usually low-key pediatric neurologist, won running as a pragmatist with the state 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.

The general election is expected to be an early referendum on the president and a preview of what the 2018 midterm elections will look like. Virginia is one of only two states electing new governors this year, 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.

At Northam’s event in Arlington, there were cheers and high fives as news spread that he had been declared the victor.

Hyun Lee, 37, of Centreville, Virginia, 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.”

ADVERTISEMENT

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 essentially had been 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.

In the Republican race, Gillespie enjoyed a huge fundraising advantage against Stewart and state Sen. Frank Wagner as well as the support of most state Republican lawmakers. Gillespie ran largely on pocketbook issues, like lowering the state income tax rate, but kept Trump at arm’s length.

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.”

___

Associated Press reporters Ben Finley in Norfolk, Jessica Gresko in Arlington, Matthew Barakat in Woodbridge and Alanna Durkin Richer in Richmond contributed to this report.