Doug Jones won a special Senate election in Alabama on Tuesday, an upset victory after his Republican opponent, Roy Moore, faced multiple allegations of sexual misconduct.

Jones’ narrow victory was rare for a Democrat in a deep southern conservative state, and constituted what may be an indication of a backlash against the brash and bombastic style of Moore and even President Donald Trump, who endorsed him late in the race.

“Folks, I got to tell you, I think I have been waiting all my life and now I just don’t know what the hell to say,” Jones told his supporters, who gave him thunderous applause for his unexpected victory. He was joined by former NBA star Charles Barkley.

“We have shown the country the way that we can be unified,” he said, in a victory speech in which he quoted Martin Luther King Jr. and emphasized “common courtesy and decency.”

Moore refused to concede. “It is not over, and it is going to take some time,” he said, adding that there were still votes from the military overseas to be counted.

Exit polls showed that Jones benefited from higher-than-expected turnout in Democratic strongholds, and perhaps a greater-than-usual number of write-in votes.

Jones is a lawyer and former prosecutor who successfully pursued a case in 2001 and 2002 against two members of the Ku Klux Klan for their roles in the 1963 16th Street Baptist Church bombing in Birmingham, Ala.

He was given long odds of winning the seat, but the nature of the race changed in November, when The Washington Post published a story in which multiple women claimed that Moore pursued sexual relations with them when they were teenagers. Another accuser claimed that Moore sexually assaulted her when she was in her teens.

Moore denied the allegations, casting himself as the target of the media elite and a threat to the Washington establishment.

No Democrat has been elected to the Senate from Alabama since 1992, when Richard Shelby was re-elected to his seat. But Shelby switched to the Republican party two years later, and earlier this week said that he didn’t vote for Moore.

“I think, so many accusations, so many cuts, so many drip, drip, drip — when it got to the 14-year-old’s story, that was enough for me. I said I can’t vote for Roy Moore,” Shelby said on CNN.

After Jones’ victory, some Republicans expressed relief. Sen. Jeff Flake (R-Arizona) said on Twitter, “Decency wins.”

Indeed, a number of Republicans saw a potential Moore victory as an existential crisis for the party and its ability to win over moderate voters in the long term.

Had Moore been elected, it would have posed problems for Senate Majority Leader Mitch McConnell, who would have faced the prospect of seating a candidate under a cloud of allegations of sexual misconduct, or of trying to eject him and face the wrath of the GOP electorate. McConnell called on Moore to drop out, and when that didn’t happen, he said that Moore would face an ethics investigation.

Even before The Washington Post published its story about Moore’s accusers, Moore’s candidacy had exposed fissures in the Republican party in the era of Donald Trump. He was backed by Steve Bannon, Trump’s former chief strategist, and Trump gave him his endorsement last week.

Meanwhile, Moore at times bashed McConnell with almost the same fervor as he railed against Democrats and the news media.

He didn’t back off of past far-right positions, characterizing them as rooted in the Biblical law. In appealing to white evangelicals, Moore mirrored Trump’s 2016 playbook by engaging in us vs. them populist rhetoric that played on cultural divides. On Tuesday, he rode to his polling place on horseback.

Moore has said that homosexual relations should be illegal, and on Tuesday his spokesman Ted Crockett told CNN that he probably still believes it. “Homosexuality is a sin in the Biblical sense. That is where Roy Moore is and the state of Alabama is,” Crockett said. Moore also said in 2006 that Keith Ellison should not be sworn in to Congress because Ellison is a Muslim.

Moore rose to prominence with his controversial tenure as Alabama’s Supreme Court chief justice, from which he was removed in 2003 after he refused a federal court order to remove a monument to the Ten Commandments from the judicial building. More than a decade later, after he again was elected as chief justice, he came under more fire for refusing to recognize same-sex marriage despite the Supreme Court decision that legalized the nuptials.

The mix of religious zealotry and political defiance proved to be particularly potent in the Republican primary to fill Jeff Sessions’ vacant Senate seat. Moore trounced Luther Strange in the primary race, who was appointed to fill the seat and backed by McConnell and other Republicans in Washington. Trump himself initially backed Strange, but after endorsing Moore, recorded a robocall, and on Friday held a rally for Moore in Pensacola, Fla., within the coverage area of Alabama.

Trump’s support induced a great deal of consternation among some Republicans. Mitt Romney wrote last week that Moore would be “a stain on the GOP and on the nation. Leigh Corfman and other victims are courageous heroes. No vote, no majority is worth losing our honor, our integrity.”

About an hour after Jones’ victory, Trump tweeted, “Congratulations to Doug Jones on a hard fought victory. 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!”

Jones’ victory will give Democrats control of 49 Senate seats to 51 for Republicans. Democrats have had rising hopes of winning back the House in 2018, and their win on Tuesday could give them some reason for optimism about the Senate.

The Senate Leadership Fund, which has been working to expand the GOP majority in the Senate, said that Jones’ victory was a “brutal reminder that candidate quality matters regardless of where you are running. 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.”