Republican candidate for governor, Ed Gillespie, on primary election night (Steve Helber/AP)

Lt. Gov. Ralph Northam emerged from his unexpectedly tough campaign for the Democratic nomination for governor in good shape for the fall election. But Republican Ed Gillespie, who seemed to coast through the primary, suddenly looks damaged.

Northam starts with a unified Democratic Party and the promise of a helping hand from his rival for the nomination, former congressman Tom Perriello.

Gillespie saw what should have been an easy victory almost slip away, and the man who nearly stole the crown — Prince William County supervisor Corey Stewart — has withheld his endorsement.

By emulating the disruptive style of Donald Trump, Stewart found the only real vein of passionate Republican voters in a Virginia that is otherwise increasingly hostile to the new president. The fact that Stewart doesn’t seem eager to help Gillespie woo that base suggests a difficult road ahead for the party and its nominee.

Virginia Democratic candidate for governor, Lt. Gov. Ralph Northam celebrates his primary victory. (Cliff Owen/AP)

It’s an odd turn for Gillespie. The last time he was in a squeaker election, he came within an eyelash of unseating Democratic Sen. Mark R. Warner in 2014. The close loss marked Gillespie’s arrival as a serious candidate.

This time, his narrow win makes him seem weakened. He wasn’t supposed to face much of a challenge in Stewart, who focused on what seemed like an odd theme of preserving Confederate monuments, or state Sen. Frank Wagner (Virginia Beach) who never had enough resources to really threaten.

Now Gillespie’s predicament “shows a real big rift within the Republican ranks,” said Mark Rozell, dean of the Schar School at George Mason University. “They have a really solid mainstream nominee who nearly took down Mark Warner. Who can argue with that? Well, Corey Stewart and the Trump followers, apparently. And, unfortunately for Gillespie, they’re active and they’re somewhat numerous, and he still needs their votes.”

Stewart acknowledged his primary loss on Wednesday but was coy about endorsing Gillespie, saying he would not do so without assurances that Gillespie will take a harder line on some issues.

“I know he wants my endorsement, my support,” Stewart told The Washington Post. “I’m voting for the Republican ticket. There’s no question about that. The real question is, will he support my supporters. Unless he stands up and takes clear positions on defending our heritage and our history, supporting the president, cracking down on illegal immigration, those who supported me are not going to go with him.”

Buoyed by his performance Tuesday, Stewart said he is weighing a 2018 run for the Senate seat held by Democrat Tim Kaine, who is up for reelection.

Even with Stewart’s support, it’s not clear how Gillespie unifies the disparate segments of the GOP.

(Amber Ferguson,Jorge Ribas,Dalton Bennett/The Washington Post)

His edge on primary night came from populous urban and suburban parts of the state — Fairfax County, Virginia Beach, the Richmond suburbs of Chesterfield and Henrico counties — voters who could be turned off if Gillespie tacks too hard into Trump territory.

And Gillespie has never seemed comfortable with the party’s commander in chief. He never mentioned Trump at his victory party Tuesday night and was slow to endorse him during last year’s election.

There’s good reason for that. Trump’s popularity in Virginia is very low: Thirty-six percent approved of him in a poll last month by The Washington Post and the Schar School.

Both Democrats running for the gubernatorial nomination ran hard against Trump, and it seemed to energize their voters. Far more ballots were cast in Tuesday’s Democratic primary (nearly 543,000) than Republican (just over 366,000). In fact, Northam got nearly as many votes as Gillespie and Stewart combined.

Perriello, especially, made it clear from the beginning that he was running against Trump. His rise coincided with a newly aggressive stance from national progressive groups, especially Our Revolution, the group affiliated with Sen. Bernie Sanders (I-Vt.).

Sanders and his group endorsed Perriello, who drew most of his money from outside the state and made savvy use of social media to reach young voters. Perriello got national headlines — and a mention on “The Late Show With Stephen Colbert” — when he posted an online ad that showed an ambulance being crushed as he promised to fight attempts to repeal the Affordable Care Act.

The main question for Northam is whether Perriello’s backers will swing his way in the general election. Perriello was quick to endorse Northam on Tuesday night and had been scheduled to attend a Democratic unity event Wednesday in Northern Virginia that was canceled in the wake of the morning’s politically motivated shooting on a baseball diamond in Alexandria.

But one issue sharply divided Northam and Perriello and could complicate their efforts to unify: the construction of two natural gas pipelines in rural parts of the state. Perriello was the only candidate to stand against them, which helped him win support in red-leaning districts in southern and western areas.

Northam never took a hard stand, saying only that the pipelines should be subject to strict environmental review. He also has taken large campaign donations from Dominion Energy, builder of one of the pipelines. Those positions infuriated many of the new progressive groups.

In interviews, several progressives and environmentalists who backed Perriello said they would also support Northam – perhaps begrudgingly. But they feared young and rural voters inclined to support Perriello would just stay home in November.

“There were so many people who were unwilling to knock doors for Hillary Clinton, unwilling to cajole friends into voting for Hillary Clinton,” said Ross Mittiga, who launched an unsuccessful primary challenge to House of Delegates Minority Leader David J. Toscano (D-Charlottesville) based on opposition to pipelines. “Northam runs the same kind of risk. He has profoundly alienated the source of the most important energy for electoral energy on the left, which is the no-pipeline movement and more broadly the environmentalist movement.”

Some pipeline opponents sent a clear signal by crashing Northam’s election night party in Crystal City and storming the stage with anti-pipeline banners.

“We are absolutely not going to stand behind Northam until he stands out against the pipeline,” said Luca Connolly, an organizer with the Virginia Student Environmental Coalition that disrupted Northam’s election party. “Really, the only way we see ourselves supporting him is if he continues to move farther left.”

Northam may be able to afford lost votes in rural areas and college towns if he pursues the same “urban crescent” strategy of ramping up margins in vote-rich northern Virginia, Richmond and Hampton Roads that helped deliver Gov. Terry McAuliffe a narrow victory in 2013. But Perriello has warned that such an approach undermines a governor’s negotiating hand and can hurt the party’s prospects in the long run.

The prospect of Perriello’s backers standing by Northam is daunting to some Republicans.

“I am worried about the fall because the left is going to be excited by their hatred of Trump,” said Mark Lloyd, who was Trump’s Virginia campaign director. “It will be their total motivation.”

The only comparable phenomenon on the Republican side was the rabid core of support for Stewart. Gillespie “doesn’t excite anybody” and “ran a messageless, boring, typical GOP campaign,” Lloyd said. “He was wonky. There’s no excitement. None.”

Stewart seems prepared to keep Gillespie on the hook awhile as he decides what to do with his army of supporters and ponders a 2018 challenge to Kaine.

But Stewart said he’s not ready to confront his political future just yet. “I’ve got to take a breather and take stock,” he said.

Jenna Portnoy contributed to this report.