Ed Gillespie begins his general election campaign for the Virginia governorship as a tottering Republican nominee, rattled by a razor-thin primary victory that exposed sharp fault lines in a party still wrestling with a mutinous tide of anti-establishment fervor that was punctuated last fall by the election of President Donald Trump.

It wasn't supposed to be this way.

The shortsighted assumption heading into Tuesday night's primary in the Old Dominion State was that it would showcase a recovering and divided Democratic Party, which was forced to choose between a moderate lieutenant governor rooted in the firmament of the party and a liberal insurgent attempting to usher in a more progressive posture.

But the highly tracked race between Ralph Northam and Tom Perriello was not even close.

Northam, the choice of party leadership, easily disposed of the Bernie Sanders and Elizabeth Warren – endorsed Perriello by nearly 12 percentage points – and Perriello quickly conceded and pledged unity.

To almost universal surprise, it was the sleepier and less covered GOP contest that dragged into the night, with Gillespie, a former chairman of the Republican National Committee and Corey Stewart, a former state chairman of the Trump campaign, separated by just a few thousand votes. Gillespie managed to hold on – but only by just over one percentage point, or about 4,300 votes.

The exceedingly close finish for the well-funded and better-known Gillespie immediately set off alarm bells among Republicans that the movement Trump unleashed and rode to the White House remains a vibrant force that's yet to have been tamed. It also means that Gillespie will be compelled to court this rebellious faction, while at the same time attempting to appeal to the independent and swing voters necessary to clinch a statewide win in Virginia.

It will not be an easy balancing act; some think it might be impossible. Together, Gillespie and Stewart netted only about 12,000 more votes than Northam did alone, a gaping turnout disparity between the parties' that indicates an enthusiasm gap.

Stewart, a Prince William County supervisor, campaigned on preserving state monuments to honor the Confederacy, deporting undocumented immigrants residing in jails and removing restrictions on gun rights. He labeled Gillespie a "cuckservative" -- a term coined by the "alt-right" meant to degrade one's conservative credentials. And he unflinchingly aligned himself with Trump, repeatedly needling Gillespie for distancing himself from the president throughout the campaign.

Given that 42 percent of the Republican electorate in Virginia supported Stewart – and another 14 percent cast ballots for state Sen. Frank Wagner, a third moderate candidate – one of Gillespie's first challenges will be deciding how strongly to embrace Trump, who will surely become a focal point in the race against Northam. The Democratic candidate pointedly used Trump in his campaign ads, calling him a "narcisstic maniac."

If he keeps the president at arm's length, Gillespie risks alienating a base who will feel no incentive to turn out this November. If he embraces Trump, he may push swing voters safely into Northam's corner.

Trump backers say the result showed Gillespie really had no choice.

"If Gillespie wants to win over Republicans who voted for Corey then he needs to make his support for President Trump and the president's agenda clear. Gillespie cannot win in November without a big turnout from the pro-Trump base, to counter the clearly motivated progressive left, and that base won't turn out for a candidate who refuses to embrace the president's agenda," says Chris Barron, a pro-Trump conservative strategist in Manassas, Virginia.

"The race to the right has clearly been a problem for Ed Gillespie, as he is heading into the general election without the majority of the Republican base at his side," Susan Swecker, chairwoman of the Virginia Democratic Party, said in a statement.

No matter which strategy Gillespie chooses, Democrats have already made moves to tie them together.

In his first post-primary email to supporters, he pledged, "We aren't going to let Ed Gillespie bring Donald Trump's hate into Virginia." The comment was made before Wednesday's early-morning shooting at a GOP congressional baseball practice. The shooter appeared to have anti-GOP leanings and had worked as a volunteer for Bernie Sanders, who decried the incident. Both sides canceled scheduled campaign events on Wednesday.

The state Democratic Party has also launched TrumpGillespie2017.com, instructing visitors that "a vote for Ed Gillespie is a vote for Donald Trump."

Gillespie managed to stay out of the Trump hornet nest during his primary run, largely sticking to local issues and declining to weigh in on the daily issues surrounding the president. That won't be possible for much longer, given that he's the standard-bearer in the marquee election of the year.

As Tuesday evening's returns piled in Stewart retweeted a message Tuesday night that said: "The death of Trumpism has been greatly exaggerated."

But Gillespie has good reason to tread carefully. Trump lost Virginia to Hillary Clinton by 5 percentage points last fall and a March survey put the president's approval rating in the state at just 37 percent. Inevitably, Gillespie will not only have to choose to embrace Trump rhetorically, but decide whether he'll want to appear with him physically on stage.

On top of that dynamic, there's also the glaring fact that Democrats have won every statewide election since 2009, leaving the starting odds stacked against Gillespie.

A Perriello victory would have emboldened progressives while making it an easier caricature for Republicans, who would've painted him as far too ideological for a state that has largely governed from the center.

Though he's put forward a largely progressive agenda, Northam will be more difficult to turn into a liberal sycophant.

After squeaking through the primary, Gillespie's campaign tried to paper over the fallout by issuing a 1,400-word memo to argue that the race with Northam is a dead heat, touting its volunteers and resources and spinning the cost of Northam's victory.

But one word that never appears in the Gillespie memo is the factor that will loom largest: Trump.