This time, Donald Trump’s playbook didn’t work.

Republican Roy Moore faced serious accusations of sexual misconduct in his bid to become Alabama’s next senator. But instead of bowing down and backing out, he stayed in the race and went on the attack ― just like Trump did in last year’s presidential race. He accused the media and the establishment of orchestrating a conspiracy against him, and cast the race as pitting good against evil, Christians versus everyone else.

Both Trump and Moore bet that their conservative base would stick by them and push them to victory.

But on Tuesday, Alabama sent a message that this time it wouldn’t work, not even in a conservative state that Trump won by 28 percentage points in 2016.

Voters instead elected Doug Jones, making him the first Democrat to win a U.S. Senate seat in the state in 25 years. The Associated Press called the race for Jones 2½ hours after polls closed in the state.

“We have shown the country the way that we can be unified,” an ecstatic Jones said in his victory speech Tuesday night.

When Jeff Sessions stepped down as senator nine months ago to become Trump’s attorney general, it was considered a sure bet that the seat would remain in GOP control.

But then Moore came along, defeating the establishment choice in the Republican primary and giving Democrats a glimmer of hope that they could win ― or at least do better than they thought possible in Alabama.

Some Moore supporters were in disbelief Tuesday night.

Willie Casey, 70, a Republican from Birmingham who was standing outside the Moore watch party, said there “has to be a recount.”

“It was tight. I’m disappointed,” he told HuffPost. “I think [Sen. Richard] Shelby coming out against him made a huge difference, but I also think the whole thing is suspicious.”

Moore himself refused to concede as well. Speaking to supporters at his election night party, Moore suggested the possibility of demanding a recount, saying, “God is still in control.”

The controversial Moore, 70, had long been known for his conservative religious beliefs, opposing equal rights for Muslims and the lesbian, gay, bisexual, transgender and queer community. And though he won statewide races for chief justice of the Alabama Supreme Court, his vote counts underperformed compared with other Republicans on the ballot.

Then in November, The Washington Post published an article in which four women accused Moore of pursuing them when they were teenagers and he was in his 30s. One of them said she was 14 when he sexually assaulted her.

After that story came out, more women came forward with similar stories about Moore.

Even after the bombshell allegations, Democrats were skeptical Jones, 63, could win. It was still Alabama, a state that Republicans dominate. But the Jones campaign set about focusing on three goals: 1) expand the Democratic electorate, especially by getting more African-American voters to turn out; 2) persuade some Republicans disgusted by Moore to vote for Jones; 3) hope other Republicans would simply stay home.

National Democrats tried to help out by staying quiet. Associating with the party wouldn’t help Jones, who was trying to emphasize that he would work across the aisle and not be beholden to people like Senate Minority Leader Chuck Schumer (D-N.Y.) and House Minority Leader Nancy Pelosi (D-Calif.).

Democrats also got lucky with Jones, who had a strong biography (he was a U.S. attorney who prosecuted Ku Klux Klan members for a 1963 church bombing that killed four African-American girls) and made few major missteps during the campaign.

While Republicans are no doubt unhappy to lose a Senate seat, there are also some sighs of relief. There’s a solid case to be made that they’ll be able to win it back during the regular election in 2020, if they have a more traditional candidate. And now, they won’t have to constantly be on the defensive about being a party that harbors an accused child molester.

They will still, however, have to contend with being the party that has a man accused of sexual misconduct by 19 women sitting in the White House.

Justin Sullivan/Getty Images Democrat Doug Jones pulled off a surprise upset in Alabama's special election Tuesday.

Moore supporters immediately began blaming the GOP establishment. Shelby, publicly condemned Moore and refused to vote for him, has earned the ire of many conservatives in the state recently. But Roger Bowman, 67, a Moore supporter from Millbrook, told HuffPost that Trump was also to blame for endorsing Moore’s opponent, Sen. Luther Strange (R-Ala.), in the primary.

“I’m seriously angry. I’d like to say something to those establishment Republicans about this. That man [Jones] is a baby killer and we’re gonna put him in office?” Bowman said, referring to Jones’ support for abortion rights. “I have absolutely no use for Shelby now, I think he’s an idiot. I think Trump should have stayed out of Alabama helping Luther Strange like that. I’m a man who votes based on the scripture, and we didn’t get that tonight.”

Chanel Rion, the 27-year-old fiancee of Missouri Senate candidate Courtland Sykes, said Jones’ win was a victory for Senate Majority Leader Mitch McConnell (R-Ky.) who fought against Moore in the primary and was critical of him throughout the race.

“There’s blood in the water for Mitch McConnell, it leads back to him. This room is gonna be walking out with a vengeance. We know who’s responsible,” she said at Moore’s party.

“This election has proven that if three floozies and a fake headline can steal an election, then they’re gonna use this as a template to go further,” she added.

Special elections aren’t reliable predictors for what will happen during a regular election. But Jones’ win gives a boost to the resistance movement that formed after Trump’s victory last year, and it underscores the importance for the party of investing in all 50 states ― so that when a Moore-like opportunity comes around, Democrats are ready to take advantage of it.

It also showed yes, there are some allegations too grotesque for voters to stomach, even when a candidate follows Trump’s playbook.

Amanda Terkel reported from Washington and Andy Campbell reported from Alabama.