Republican Glenn Youngkin has been elected as Virginia's next governor in a major upset, with his Democratic opponent conceding the race.
The ballot has been widely seen as a referendum on Joe Biden's presidency, and defeat will unnerve the Democrats.
He won by 10 points in Virginia in the presidential election just a year ago.
But rising inflation, a slow economic recovery, a deadlocked legislative agenda and the chaotic withdrawal from Afghanistan have hit his popularity.
In a speech to cheering supporters, Mr Youngkin promised to get to work straight away to transform the state.
"We work in real people time, not government time," the Republican declared.
Mr McAuliffe served as governor from 2014-18. His opinion poll lead vanished in recent weeks, and in a statement after his loss said he had "come up short" but insisted the state remained on a path towards "inclusion, openness and tolerance for all".
The state's current, Democratic governor, Ralph Northam, was unable to stand for re-election as Virginia does not allow governors to serve consecutive terms in office.
In more potential good news for Virginia Republicans, their candidate, former US Marine Winsome Sears, is tipped to become the first black female lieutenant governor of the state, which was the former seat of the pro-slavery Confederacy during the American Civil War.
The Republican candidate for Virginia attorney general, Cuban American Jason Miyares, was also leading that vote count. And Republicans seemed to be closing in on control of the state's House of Delegates.
In other elections across the US on Tuesday:
- In New Jersey, Republican challenger Jack Ciattarelli is neck and neck with Democratic Governor Phil Murphy
- Amid surging crime, Minneapolis voters rejected a proposal to replace the city's police department with a new Department of Public Safety, more than a year after the murder of George Floyd by an officer
- As expected, Democrat Eric Adams won New York City's mayoral election to replace his party colleague Bill de Blasio; Republican challenger Curtis Sliwa was involved in an argument at his polling station after turning up to vote with a pet cat and being told his furry friend Gizmo could not enter
- Pittsburgh picked its first black mayor, Democrat Ed Gainey
In Boston, Asian-American candidate Michelle Wu was elected mayor, becoming the first woman and first person of colour to take the post.
"One of my sons asked me the other night if boys can be elected mayor of Boston," the Democrat told supporters. "They have been, and they will again some day, but not tonight."
How did a Republican win in Virginia?
Mr Youngkin is the first member of his party elected to statewide office in Virginia since 2009.
The political newcomer focused during the bitterly fought election on crime and the economy, as well as how schools handle race, gender and mask mandates.
Mr McAuliffe campaigned on other cultural issues, such as abortion rights and voting reform.
But the Democrat's critics hammered him for saying during a debate: "I don't think parents should be telling schools what they should teach."
According to exit polls by the BBC's US partner, CBS, education and the school curriculum were top issues for slightly more than half of all voters.
At a news conference earlier on Tuesday, Mr Biden predicted his party would win the first major election since he took office 10 months ago, but he acknowledged "the off-year is always unpredictable".
The Democratic president's approval rating has fallen to 43%, according to an opinion poll average by RealClearPolitics.
The McAuliffe campaign tried to liken the challenger to former President Donald Trump, who remains unpopular in Virginia.
But Mr Youngkin, a mild-mannered private equity tycoon, sought to appeal to moderates by keeping Mr Trump at arm's length, while tapping into the former president's supporters in the state.
His balancing act may offer a template for Republicans seeking to win back suburban moderate voters who were turned off by Mr Trump's firebrand style of politics.
The race could shape party messaging and battle-plans for next year's mid-term elections, when the Democrats will defend their wafer-thin majorities in Congress, and the 2024 White House election.
Mr Trump thanked his supporters for "coming out in force and voting for Glenn Youngkin", saying the MAGA movement was "bigger and stronger than ever before".
The Trump playbook without Trump
By Tara McKelvey, BBC News, Fairfax, Virginia
The restaurant was crowded, with people angling for the best place to watch election returns on big screens, with American flags everywhere.
They had gathered hoping to see Glenn Youngkin win.
Over the past several months, he has charted a course for conservatives - he talks frequently about race relations, and has denounced the teaching of critical race theory.
He ran on a law-and-order platform, and opposed mask mandates, and his messaging echoed the kind that Mr Trump uses. But Mr Youngkin kept his distance from the former president.
In this way, Mr Youngkin has appealed to voters who like Mr Trump's positions, but are uneasy about the man himself.
His win is likely to guide other conservatives in their campaigns for the congressional midterms.