Democrat Doug Jones scored a once-unthinkable victory Tuesday, winning a U.S. Senate seat in deep-red Alabama fueled by a surge in turnout and a wave of Republicans who couldn't support former judge Roy Moore's candidacy after he was accused of sexual misconduct.

Jones pulled off the upset by scoring huge margins in Alabama’s urban areas and holding Moore to lower totals in rural counties he needed to carry by overwhelming totals. The high rate of write-in votes from primarily Republican voters – about 2 percent – helped put Jones over the top.

Jones’ victory was a stinging blow to President Donald Trump, who wholeheartedly endorsed Moore in the final days of the race even as other Republican figures abandoned him. And it narrows the GOP edge in the U.S. Senate to a single vote.

Seeming almost stunned he won - "I just don't know what the hell to say," Jones quipped as he took the stage - the Democrat cast his victory in sweeping terms. He urged the U.S. Senate to take his win as a sign that lawmakers should quickly fund the Children's Health Insurance Program.

"Alabama has been at a crossroads," he said. "We have been at crossroads in the past and unfortunately we have usually taken the wrong fork. Tonight, ladies and gentlemen, you took the right road."

Moore said he was unwilling to concede and blamed the media for painting him in an “unfavorable light” in brief remarks to a crowd of supporters who chanted “USA” as he spoke. Alabama law requires a mandatory recount if the margin is within 0.5 percent of the vote; Jones led by about 1.5 percent.

“When the vote is this close, it’s not over,” Moore said. “We still have to go by the rules, by this recount provision.”

A former federal prosecutor, Jones wasn’t ever expected to make this a competitive race. Trump carried Alabama by 28 percentage points last year, and the state hasn’t elected a Democrat for Senate or governor in nearly two decades. The party’s retreat left its infrastructure in tatters.

But Moore struggled with a segment of Alabama’s deep-red Republican base even before he was stung by a string of sexual misconduct allegations that he courted teenagers when he was in his 30s. He’s denied those claims.

Moore’s strategy depended almost entirely on winning huge margins in rural counties that Trump won by whopping majorities – and that helped carry Moore to a pair of statewide election wins.

Jones relied on a trickier formula. He had to energize the party’s black voters, who make up about a third of the electorate, while winning over a significant chunk of voters who typically cast ballots for Republicans but were disgusted by Moore.

The results streaming in late Tuesday showed it worked. He carried Jefferson County, which encompasses Birmingham, with about 70 percent of the vote. He took Montgomery County, home of the state capital, by an even bigger haul. And he won a string of conservative-leaning counties where Democrats have struggled for decades.

In a tweet late Tuesday, Trump congratulated Jones for a "hard-fought victory" and issued a reminder that Jones will face a tough reelection battle in three years. "The write-in votes played a very big factor," the president wrote, "but a win is a win."

Georgia Democrats, who aimed to tie Moore to their GOP rivals, immediately seized on Jones’ victory. Stacey Abrams, a former Georgia House leader, sent a fundraising plea minutes after the race was called.

“This is a huge win for Democrats, for decency in politics – and a big blow to Trump and his exclusionary agenda that harms working families,” it read. “It also means that the ‘blue wave’ we saw sweep through Virginia last month has moved to the Deep South - to our own backyard.”

Other Democrats made clear they plan to make Moore a running-mate for other Republicans even after he lost. State Rep. Scott Holcomb, D-Atlanta, said Republicans "went all in and lost. And voters won't quickly forget that they supported a sexual deviant who preyed on teenagers."

Some Georgia Republicans vented their anger at Senate Majority Leader Mitch McConnell, who withheld his endorsement - and funding - from Moore's campaign. In a tweet, state Sen. Michael Williams said "McConnell and the establishment failed Republicans."

"They focused on how to trash Moore if he won rather than get out the vote. The swamp must be drained. Republicans praising Moore's loss are complicit in the deaths of thousands of babies & open borders," wrote Williams, a candidate for governor.