MONTGOMERY, Ala. — Democrat Doug Jones shocked this state, and the country, by defeating Republican Roy Moore in Alabama’s Senate special election Tuesday, a victory that sounds a loud warning to the White House and the Republican Party.

President Trump had thrown his full support behind Moore, who was a controversial figure even before multiple allegations emerged that he had pursued inappropriate relationships with teenagers as an adult.

Jones’s victory is a shot in the arm for Democrats, who are hoping that anger at Trump and congressional Republicans will fuel a “wave” election in 2018, flipping the U.S. House of Representatives, and perhaps even the Senate, blue.

“Tonight is a night for rejoicing,” Jones told a jubilant crowd in Birmingham after defeating Moore 670,551 votes to 649,240, with 100 percent of the vote counted.

Jones, a former U.S. attorney who prosecuted Ku Klux Klan members for an infamous 1963 church bombing in Birmingham, will be the first Democrat to represent Alabama in the Senate in 20 years. He fills the seat left vacant by Attorney General Jeff Sessions.

Moore’s defeat means that Trump has now suffered three consecutive losses. He first backed Moore’s opponent, Luther Strange, in the Republican primary only to see him lose to Moore. Then, last month, voters in Virginia turned out in historic numbers to deliver a massive rebuke to Trump in the elections for governor and state legislature.

Nonetheless, Trump put forth his best face Tuesday night. “Congratulations to Doug Jones on a hard-fought victory,” the president tweeted. “The write-in votes played a very big factor, but a win is a win. The people of Alabama are great, and the Republicans will have another shot at this seat in a very short period of time. It never ends!”

Moore gave brief remarks to his supporters, but did not concede the race, saying a recount was still possible. But state law requires a half-point margin or less to trigger a recount, and Jones bested Moore by 1.5 points.

Story continues

Roy Moore leaves the stage after speaking in Montgomery, Ala., Dec. 12, 2017. (Photo: Mike Stewart/AP)

After suffering decades of stinging losses, Alabama Democrats celebrated a historic night. House Minority Leader Anthony Daniels, who is just 35 years old, pledged that it would spark a resurgence for the party.

“This is just the beginning,” Daniels said in a phone interview. “This gives us the momentum we need.”

But it wasn’t just Democrats who were overjoyed by the result Tuesday night. Alabama is an overwhelmingly Republican state, and Jones received votes from many in the GOP who could not abide the thought of Moore winning. There were more than 22,000 write-in ballots cast, making up almost two percent of the electorate.

After Jones was declared the winner, a veteran Republican in the state, Hatton Smith, reached us by phone. Smith, who was an adviser to Luther Strange in the Republican primary, said, “We got a bunch of Republicans here that want to tell you something.”

He held up his phone and the sound of a group of people cheering loudly came over the phone.

“It’s good over evil,” Smith said. “The state of Alabama won.” He added: “Here’s to 2020 when we defeat Doug Jones.”

Moore, a former judge who was removed from office twice before running for the Senate, was hit by multiple allegations from women who said he sexually pursued them when he was in his 30s and they were teenagers. One woman said Moore touched her sexually when she was 14; another said he sexually assaulted her when she was just 16 years old and he was an assistant district attorney.

Moore vehemently denied the allegations, but several high-profile Republicans, including Senate Majority Leader Mitch McConnell, said they believed the women. Trump, however, never abandoned Moore, even recording a robocall for him in Alabama that decried Jones as a “puppet of Nancy Pelosi and Chuck Schumer.” Trump won the state last year by 28 points, and his failure to push Moore over the finish line could spell trouble for the unpopular president’s political strategy going forward.

Jones’s victory also endangers Republicans’ tax reform legislation in Congress, which passed by a narrow majority in the Senate earlier this month. Both the Senate and the House will have to pass another combined version of the tax bill to send it to the president’s desk. With one fewer Republican in the chamber, McConnell can lose only one vote and still push through the bill, which has not attracted any Democratic support. Sen. Bob Corker, R-Tenn., has already voted against the legislation once, and Sen. Susan Collins, R-Maine, has made several demands regarding health care that must be met before she’ll support it again. McConnell could rush the vote before Jones is seated in January, however.

Supporters celebrate at the election night party for Democratic Alabama U.S. Senate candidate Doug Jones in Birmingham, Ala., on Dec. 12. (Photo: Marvin Gentry/Reuters)

Sen. Cory Gardner, R-Colo., who chairs the Senate GOP’s campaign arm and pulled the group’s support for Moore after the allegations of sexual misconduct became public, began immediately Tuesday night to recruit Jones to join the Republican Party.

“The people of Alabama deemed Roy Moore unfit to serve in the U.S. Senate,” Gardner said in a statement in which he called on Jones to “do the right thing and truly represent Alabama by choosing to vote with the Senate Republican majority.”

The result was also a stinging setback for former White House strategist Steve Bannon, who left the administration in August and immediately made Moore his No. 1 cause. He used Breitbart News, which he runs, as a vehicle to prop up the Republican, and appeared poised to accrue significant influence if Moore was elected to the Senate.

Now Bannon will have to look for a new vehicle and remains without any significant electoral wins as a power broker.

Steven Law, who runs the Senate Leadership Fund, a super-PAC affiliated with McConnell, the Senate majority leader, delivered a cutting criticism of Bannon’s work.

“This is a brutal reminder that candidate quality matters regardless of where you are running,” Law said in a statement. “Not only did Steve Bannon cost us a critical Senate seat in one of the most Republican states in the country, but he also dragged the president of the United States into his fiasco.”

Jones ran a vigorous campaign up to the end, targeting the state’s black population last weekend. He brought in Sen. Cory Booker, D-N.J., and Rep. Cedric Richmond, D-La., to stump for him. Jones also ran ads featuring prominent Republicans, including Sen. Richard Shelby, R-Ala., disavowing Moore, in a bid to peel off conservatives.

Meanwhile, Moore lay low, holding no campaign events until a rally Monday with Bannon. “If you don’t believe in my character, don’t vote for me,” Moore said then.

Moore was already a controversial figure in Alabama. While serving as the chief justice of the state Supreme Court, he twice was ordered to remove a monument to the Ten Commandments from the courthouse and both times refused. Moore’s record on race is marked by opposition to removing Jim Crow language from state statues, and he just recently said America was last great during a time when blacks were enslaved.

While many religious conservatives in the South might not be enthusiastic about gay marriage, Moore’s harsh language about gays has been another turnoff for moderate Alabamans. And his antagonism of African-Americans motivated higher than normal turnout by minority voters in what would usually be a sleepy off-year election less than two weeks before Christmas. African-Americans made up a higher percentage of the electorate Tuesday, at 30 percent, than they did in 2008 and 2012, when former President Barack Obama was on the ballot. Blacks were 29 percent of the vote in 2008 and 28 percent in 2012.

For establishment Republicans who had distanced themselves from Moore’s candidacy, the election of a Democrat came as welcome news.

Sen. Jeff Flake, R-Ariz., who has been one of the most outspoken Trump critics in the Republican Party, delivered a succinct coda to the night on Twitter: “Decency wins,” he said.

Read more from Yahoo News: