It was the first Democratic Senate victory in a quarter-century in Alabama, one of the reddest of red states, and proved anew that party loyalty is anything but sure in the age of Trump. The Republican loss was a major embarrassment for the president and a fresh wound for the nation's already divided GOP.

"We have shown not just around the state of Alabama, but we have shown the country the way -- that we can be unified," Jones declared as supporters in a Birmingham ballroom cheered, danced and cried tears of joy. He added, "This entire race has been about dignity and respect."

From the White House, Trump graciously tweeted his congratulations to Jones "on a hard-fought victory" — but added pointedly that "the Republicans will have another shot at this seat in a very short period of time. It never ends!"

Jones takes over the seat previously held by Attorney General Jeff Sessions. The term expires in January of 2021.

The victory by Jones, a former U.S. attorney best known for prosecuting two Ku Klux Klansmen responsible for Birmingham's infamous 1963 church bombing, narrows the GOP advantage in the U.S. Senate to 51-49. That imperils already-uncertain Republican tax, budget and health proposals and injects tremendous energy into the Democratic Party's early push to reclaim House and Senate majorities in 2018.

Still, many Washington Republicans viewed the defeat of Moore as perhaps the best outcome for the party nationally despite the short-term sting. The fiery Christian conservative's positions have alienated women, racial minorities, gays and Muslims -- in addition to the multiple allegations that he was guilty of sexual misconduct with teens, one only 14, when he was in his 30s.

"Tonight's results are clear -- the people of Alabama deemed Roy Moore unfit to serve in the U.S. Senate," said Colorado Sen. Cory Gardner, who leads the national GOP's Senate campaign arm and called on Moore to quit the race weeks ago.

“On a very personal level, I want to thank each of you for fulfilling a lifelong dream to serve in the U.S Senate.

A number of Republicans declined to support him, including Alabama's long-serving Sen. Richard Shelby. But Trump lent his name and the national GOP's resources to Moore's campaign in recent days.

Had Moore won, the GOP would have been saddled with a colleague accused of sordid conduct as Republicans nationwide struggle with Trump's historically low popularity. Senate leaders had promised that Moore would have faced an immediate ethics investigation.

Republicans on Capitol Hill have expressed hopes of scheduling a vote on their tax legislation before Jones is sworn in, but lawmakers are still struggling to devise a compromise bill to bridge the divide between the House and Senate legislation that can win majority support in both chambers.

The Republican loss also gives Democrats a clearer path to a Senate majority in 2018 -- albeit a narrow one -- in an election cycle where Democrats are far more optimistic about seizing control of the House of Representatives.

Ultimately, Tuesday's contest came down to which side better motivated its supporters to vote. Alabama Secretary of State John Merrill said turnout likely would not exceed 25 percent of registered voters.

Jones successfully fought to cobble together an unlikely coalition of African-Americans, liberal whites and moderate Republicans.

Doug Jones mingled with voters outside a polling station in Bessemer, Ala., on Tuesday.

(Justin Sullivan/Getty Images)

U.S. Senate candidate Roy Moore supporter Charles Moore prays with his son Ethan Moore during an invocation at an election-night watch party at the RSA activity center for Moore, Tuesday, Dec. 12, 2017, in Montgomery, Ala. (AP Photo/Brynn Anderson)

(Brynn Anderson/AP)

BIRMINGHAM, AL - DECEMBER 12: A supporter of Democratic U.S. Senatorial candidate Doug Jones holds a sign as he watches election returns during an election night gathering the Sheraton Hotel on December 12, 2017 in Birmingham, Alabama. Doug Jones is in a tight race with Republican challenger Roy Moore to fill Attorney General Jeff Session's seat. (Photo by Justin Sullivan/Getty Images)

(Justin Sullivan/Getty Images)

A supporter of Roy Moore, the Republican candidate for U.S. Senate, at an election-night party in Montgomery, Ala., Dec. 12, 2017. Alabama voters went to the polls Tuesday to decide between Roy Moore, a Republican, and Doug Jones, a Democrat, in a special Senate election destined to be remembered as a strange and ugly campaign carrying immense political implications. (Audra Melton/The New York Times)

(AUDRA MELTON/NYT)

MOUNTAIN BROOK, AL - DECEMBER 12: Democratic senatorial candidate Doug Jones speaks to reporters after voting at Brookwood Baptist Church on December 12, 2017 in Mountain Brook, Alabama. Doug Jones is facing off against Republican Roy Moore in a special election for U.S. Senate. (Photo by Justin Sullivan/Getty Images) *** BESTPIX ***

(Justin Sullivan)

The polling place at Galloway Park Community Center in Brundidge, Ala., Dec. 12, 2017. Alabama voters went to the polls Tuesday to decide between Roy Moore, a Republican, and Doug Jones, a Democrat, in a special Senate election destined to be remembered as a strange and ugly campaign carrying immense political implications. (Audra Melton/The New York Times)

MONTGOMERY, AL - DECEMBER 12: Republican Senatorial candidate Roy Moore walks with his wife Kayla Moore after saying the race against his Democratic opponent Doug Jones is too close and there will be a recount during his election night party in the RSA Activity Center on December 12, 2017 in Montgomery, Alabama. The candidates are running in a special election to replace Attorney General Jeff Sessions in the U.S. Senate. (Photo by Joe Raedle/Getty Images)

(Joe Raedle/Getty Images)

Doug Jones, the Democratic candidate for U.S. Senate, celebrates his presumed victory during his watch party in Birmingham, Ala., Dec. 12, 2017. Jones won the special election on Tuesday to fill the United States Senate seat vacated by Jeff Sessions, now the attorney general, according to The Associated Press. (Bob Miller/The New York Times)

(BOB MILLER/NYT)

At his election night headquarters, stunned supporters erupted in celebration as news of his victory was announced. Many danced to the song "Happy." Some cried.

"I honestly did not know that this was even an option. I didn't think that we could elect a Democrat," said 26-year-old campaign volunteer Jess Eddington, her eyes red from tears of joy. "I am so proud we did."

On the ground in Alabama on Tuesday, voters made clear that the election was about opposing Moore as well as supporting Jones, who was largely unknown before the campaign.

Teresa Brown, a 53-year-old administrative assistant, said she preferred Jones, in part, because he would be better positioned to work across party lines. "We don't need a pedophile in there," Brown added.

Mary Multrie, 69, who works in a children's hospital, said she never liked Moore. "He talks about God, but you don't see God in his actions."

Moore, who largely avoided public events in the final weeks of the race and spent far less money on advertising than his opponent, bet big -- and lost -- on the state's traditional Republican leanings and the strength of his passionate evangelical Christian supporters.

He sidestepped questions about sexual misconduct as he arrived at his polling place on horseback.

Democrats were not supposed to have a chance in Alabama, one of the most Republican-leaning states in the nation. Trump defeated Democrat Hillary Clinton here by nearly 28 points just 13 months ago. Yet Moore had political baggage that repelled some moderate Republicans even before allegations of sexual misconduct surfaced.

Moore was once removed from his position as state Supreme Court chief justice after he refused to remove a boulder-sized Ten Commandments monument at the state court building. A second time, he was permanently suspended for urging state probate judges to refuse marriage licenses to same-sex couples.

Said Democratic National Committee Chairman Tom Pere: "The people of Alabama sent a loud and clear message to Donald Trump and the Republican Party: You can't call yourself the party of family values as long as you're willing to accept vile men like Roy Moore as members."