Democrats look set to hold Virginia’s governorship after an ugly race seen as a political cardiogram of the US a year after President Trump’s election.
Projections suggest Ralph Northam beat Republican Ed Gillespie after a campaign marked by tussles on immigration and Confederate statues.
Virginia voters also made history by electing their first openly transgender state legislator.
The race could be a bellwether of next year’s midterm congressional elections.
Mr Northam, the lieutenant governor of Virginia, was the front-runner though opinion polls had narrowed in the closing stretch, jangling Democratic nerves.
He and Mr Gillespie, a Washington lobbyist and former Republican party chairman, were vying to replace popular Governor Terry McAuliffe, a Democrat.
Democrats have been craving something to celebrate after defeat in four congressional special elections this year, despite a groundswell of grassroots opposition to President Trump.
The contest was the most closely watched out of a series of state and local races nationwide on Tuesday.
In New Jersey, Democrat Phil Murphy looks set to comfortably win the race to succeed unpopular Republican governor Chris Christie.
In New York, Democratic Mayor Bill de Blasio was re-elected.
Meanwhile, Virginia voters elected their first openly transgender state legislator in Danica Roem.
The 32-year-old journalist and stepmother ousted a longtime, pro-Trump, incumbent Republican in a race that focused on traffic issues.
Her rival, Bob Marshall, described himself earlier this year as Virginia’s “chief homophobe”.
Reasons for Republicans to worry
Analysis by Anthony Zurcher, BBC News, Washington
Democrats finally have a victory of the non-moral kind. After coming up short in a handful of special elections across the US, they went to the polls in a battleground state and posted a huge win.
How the Democrats, from governor candidate Ralph Northam on down, swept through election night in Virginia should be particularly concerning to Republicans across the US.
Turnout from Democratic supporters surged. They ran up huge margins with college-educated voters and residents in the wealthy Northern Virginia suburbs. The legions of rural voters who turned out for Donald Trump in 2016 were a non-factor.
Democrats won legislative races that were considered to be in play only in the rosiest of Democratic wave scenarios. Exit polls show a plurality of Virginians went to the polls to send a message to Mr Trump. Their top issue was healthcare. At least in Virginia, the president’s dismal approval ratings translated into ballot-box poison.
The stage is now set for the midterm elections in 2018. Republicans will have a year to brace for what could be an anti-Trump tsunami forming on the horizon. What they – and Mr Trump – do next could decide their fate.