Ed Gillespie barely hung on in his bid for the Republican nomination for Virginia governor, defeating Corey Stewart by less than 1 percentage point.

Gillespie was leading Stewart 43.53 percent to 42.86 percent with more than 94 percent of precints reporting. State Sen. Frank Wagner was in third with 13.61 percent of the vote.

Gillespie, the establishment favorite who was better funded and better organized, was expected to cruise to victory over Stewart, Prince William County Council chairman. Instead, Gillespie, the 2014 GOP Senate nominee who nearly pulled off a shocker of his own in that race, spent Tuesday evening sweating as his small but consistent lead dwindled as the votes came in. At one point, Gillespie led by less than 1,000 votes.

The close finish, against a candidate who took up the cause of saving Confederate monuments down the stretch of the primary campaign to boost his flagging campaign, could portend a rough five months ahead for Gillespie against Lt. Gov. Ralph Northam, a centrist who easily won the Democratic primary over former Congressman Tom Perriello.

Turnout in the Democratic primary outpaced the three-candidate GOP primary by around 100,000 voters, possibly signaling that Northam has a larger pool of voters to pull from, a more ethusiastic electorate, or both. Gillespie also might have to contend with what could be a restless GOP base, while trying to peel off independents and soft Democrats from Northam.

That could be difficult with President Trump saddled with approval ratings that have consistently hovered around 40 percent.

The party in power in the White House usually loses the off-year Virginia governor's race, although outgoing Democratic Gov. Terry McAuliffe won in a squeaker four years ago, just after President Barack Obama was re-elected. That historical trend is a challenge for Gillespiet, especially if Trump's approval ratings don't improve over the next five months.

The race for governor in Virginia is often considered a harbinger for the midterm elections. In 2009, Republican Bob McDonnell won in a rout, presaging the GOP wave that swept Congress the following year.

Virginia is a battleground state that has tilted Democratic in statewide elections over the past dozen years. The Republicans haven't won there at the presidential level since 2004; they haven't won a Senate race there since 2002, and haven't won a gubernatorial contest there since 2009. Republicans do control the state legislature.