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.
Mr Moore has so far refused to concede. All votes have now been counted.
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.
The contest was for the seat vacated by US Attorney General Jeff Sessions earlier this year.