The victory for Democrat Doug Jones narrows the Republican majority in the Senate to 51-49, which could complicate Mr Trump’s legislative plans.
Mr Moore’s campaign was rocked by allegations of sexual misconduct made by several women, which he denied.
Mr Jones is the first Democrat to win a US Senate seat for Alabama in 25 years.
Despite top Republicans deserting ultra-conservative Mr Moore amid claims of child molestation, the US president had offered his full endorsement.
Mr Trump even recorded an automated phone message for the embattled Senate candidate in the days leading up to the election.
In his first reaction on Twitter, Mr Trump congratulated the Democratic victor Mr Jones.
But he went on to remind his followers that he initially supported Mr Moore’s mainstream Republican opponent, Luther Strange, in the party’s primary election.
He added “if last night’s election proved anything, it proved that we need to put up GREAT Republican candidates to increase the razor thin margins in both the House and Senate”.
Mr Jones told reporters at a news conference on Wednesday that he received calls from President Trump, Democratic leader Senator Chuck Schumer and his Republican counterpart, Senator Mitch McConnell.
He said Mr Trump made a “very gracious” phone call and extended an invitation to the White House.
Mr Jones added that he has not yet spoken to Mr Moore.
“I’m going to let him make that decision,” he said.
The Alabama seat was made vacant by US Attorney General Jeff Sessions earlier this year.
he ramifications of this unexpected victory are clear.
The Republican majority in the Senate will narrow, considerably improving the chances Democrats could gain control of the chamber in the 2018 mid-term elections.
It could also be seen as a rebuke of President Donald Trump, who gave full-throated support to Roy Moore even when other leaders in his party were hesitant.
After winning governor races in Virginia and New Jersey in November, some Democratic supporters will be hoping that an anti-Trump electoral wave is forming.
But Mr Moore was such a flawed candidate that it may be too early to tell.
But Alabama Secretary of State John Merrill, quoted by the Washington Post, said a recount could still be ordered if a review of write-in votes and overseas ballots narrowed it to within this range.
Even if the final result is outside the 0.5% margin, either candidate can request a recount if they are prepared to pay the costs.
Mr Jones told his supporters in a victory speech that the “entire race has been about dignity and respect”.
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. (Courtesy BBC)