Democrat Doug Jones is projected to win the Alabama Senate race, US media report.
The polls have closed in Alabama, where a firebrand Republican conservative has been battling for a Senate seat against the Democrat.
President Donald Trump's populist brand has been tested after he backed Roy Moore, who denies allegations of sexual misconduct with teenage girls.
Much of the Republican establishment has distanced itself from the 70-year-old former Alabama judge.
The race between Mr Moore and Democrat Doug Jones had been too close to call, but the Democrat snatched it by less than a percent.
The stunning upset by Mr Jones makes him the first Democrat elected to the US Senate from Alabama in a quarter-century.
And it will trim the Republicans' already narrow Senate majority to 51-49, endangering Mr Trump's agenda and opening the door for Democrats to possibly retake the chamber in next year's congressional elections.
The Republican candidate has said homosexual activity should be illegal and argued against removing segregationist language from the state constitution.
But it is sexual abuse claims against him by a number of women, some when they were teenagers, that have made Washington conservatives baulk.
One accuser alleges Mr Moore molested her when she was 14.
On Tuesday, the world's press were waiting as Mr Moore emerged on horseback from woodland to a ballot station.
He said people should "go out and vote their conscience".
Making his final pitch on election eve, Mr Moore reiterated his denials, again questioning why his accusers had kept quiet for 40 years while he had held various political offices.
Speaking alongside Mr Trump's former chief strategist, Steve Bannon, in front of a crowd that chanted the president's slogan "Drain the Swamp", Mr Moore drew heavily from the Bible.
"I want America great," he said, "but I want America good and she can't be good until we go back to God."
Mr Moore was joined at Monday's rally by his wife Kayla, who said separate allegations last week that her husband was anti-Semitic were "fake news".
"One of our attorneys is a Jew, we have very close friends who are Jewish," she said.
In an automated phone message on Monday, Mr Trump's voice warned voters that his agenda would be "stopped cold" if Mr Moore lost.
But many other leading Republicans, including Senate Majority Leader Mitch McConnell, have kept arm's length from their party's candidate, or shunned him altogether.
Without mentioning Mr Moore by name, Republican former Secretary of State Condoleezza Rice, an African-American who grew up in Alabama, urged her home state to "reject bigotry, sexism, and intolerance".
Richard Shelby, Alabama's other senator, said on Sunday the state "deserves better" than Mr Moore.
A Democratic lawmaker has sent a letter to the Senate urging steps to protect teenagers working in the chamber's page programme from Mr Moore's "predatory conduct".
Mr Jones, a 63-year-old former prosecutor, denies opponents' claims he will be a "puppet" of the Democratic congressional leadership.
He is lauded for helping convict two Ku Klux Klan members who bombed a black church in 1963 in Birmingham, killing four girls.
But Mr Jones' support for abortion rights is toxic to many Christian conservatives in Alabama.
After casting his ballot on Tuesday morning, he predicted: "I don't think Roy Moore is going to win this election."
Former President Barack Obama has recorded an automated phone message for Mr Jones.
"This one's serious," Mr Obama told voters in his call. "You can't sit it out."