RICHMOND, Va. (WVEC) -- Lieutenant Governor Ralph Northam will become Virginia's next governor after beating out Republican opponent Ed Gillespie and Libertarian candidate Cliff Hyra Tuesday.

Get The Latest: 2017 | Election Results

The Associated Press called the race for Northam at 8:12 p.m.

Virginia's hard-fought race was closely watched as a swing-state test of President Donald Trump's popularity. Northam, a pediatric neurologist and the state's lieutenant governor, repeatedly tried to tie Gillespie to the president during months of divisive campaigning overshadowed by racial overtones and attack ads.

Northam's victory was in large part due to a surge in anti-Trump energy since the president took office. Democrats said they had record levels of enthusiasm heading into the race.

Gillespie kept Trump at a distance throughout the campaign but tried to rally the president's supporters with hard-edge ads focused on illegal immigration and preserving Confederate statues.