Doug Jones has become the first Democrat in 25 years to win a US Senate seat for Alabama after a bitter campaign against Republican Roy Moore.
His unexpected victory deals a blow to President Donald Trump, who backed Mr Moore, and narrows the Republican majority in the Senate to 51-49.
With 99% of the votes counted, Mr Moore refused to concede on Tuesday night.
He fought a controversial campaign, in which allegations surfaced of sexual misconduct with teenage girls.
Mr Moore, a firebrand conservative who has said he believes that homosexual activity should be illegal, has repeatedly denied the claims against him.
Why hasn’t Roy Moore conceded?
Many media outlets have reported the election in favour of Mr Jones, and 99% of the votes have been counted.
But Mr Moore, 70, told his supporters it was not yet over.
“We’ve been painted in an unfavourable and unfaithful light,” he said. “Realise that when the vote is this close that it’s not over.”
He said he believed the margin of victory could narrow as more votes poured in, which could trigger an automatic recount.
Alabama Secretary of State John Merrill said a recount could be ordered if the margin is narrowed to less than half a percentage point.
Although Mr Moore did not concede, President Trump congratulated Mr Jones in a tweet shortly after US media declared him the winner, adding that “Republicans will have another shot at this seat in a very short period of time”.
Mr Jones told his supporters in a victory speech that the “entire race has been about dignity and respect”.
“This campaign has been about the rule of law. This campaign has been about common courtesy and decency and making sure everyone in this state, regardless of which zip code you live in, is going to get a fair shake in life,” he said before the crowd erupted in cheers.
The 63-year-old is a former lawyer known for helping convict two Ku Klux Klan members who bombed a black church in 1963 in Birmingham, killing four girls. He has never held elected office.
Mr Jones wins the seat vacated by US Attorney General Jeff Sessions earlier this year.