Democrat Senator Doug Jones has pulled off a dramatic upset by narrowly winning the senate race in the US state of Alabama, even as his Republican rival, Roy Moore, refuses to concede defeat.

Jones defeated Moore, a controversial candidate who has been accused of sexual misconduct, after a bitter campaign in which US President Donald Trump openly endorsed the Republican.

Moore’s loss is a major setback for the Republican Party, which held the Senate seat in the southern, Republican-dominated state for the past 25 years.

“We have shown – not just in the state of Alabama but across the country – that we can be unified,” Jones said in his victory speech in Birmingham late on Tuesday.

‘It’s not over’

Al Jazeera’s Shihab Rattansi, reporting from Birmingham, said that Moore refused to acknowledge his defeat and demanded a recount.

“Moore is invoking an Alabama law that requires a mandatory recount if the margin of victory is half a percent or less. The problem is that the margin of victory, as it currently stands, is one and a half percent, so it doesn’t even make sense,” Rattansi said.

“So, the secretary of state of Alabama is being rather noncommittal about a recount.”

{articleGUID}

Moore, who has been accused of rape and molesting a 14-year-old girl, told his supporters at a gathering in Montgomery late on Tuesday that he was treated unfairly in the campaign.

“Part of the problem with this campaign is that we have been painted in an unfavourable and unfaithful light … we got to wait on God and let this process play out,” Moore said after Jones claimed victory.

“The votes are still coming in and we are looking at that … it’s not over and it’s going to take some time,” Moore said.

Shortly after the results came out, Trump tweeted to congratulate Jones, but said it was not going to be long before the congressional elections come up when the Republicans could win back the Senate seat.

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! — Donald J. Trump (@realDonaldTrump) December 13, 2017

“It was a rather gracious tweet from Trump, which of course undermines Moore’s attempt to get a recount,” Rattansi said.

“But the Republican establishment in Washington, led by Senate majority leader Mitch McConnell, had already said they were not supportive of Moore. They had said that if he did win the Republicans themselves would have started an ethics investigation into Moore’s conduct.

“Those fissures, or civil war in the Republican party, is likely to intensify as a result of this loss,” our correspondent said.

‘Difference by education’

With Jones’ win in Alabama, the Republican majority in the Senate is now leaning on just one senator, with 51 Republican against 49 Democratic seats.

Speaking to Al Jazeera from Washington, DC, William Schneider, professor of public policy at George Mason University, said Moore’s defeat was a big blow to Trump.

“In the last couple of weeks, he came out in strong support of Moore, even though he never went to Alabama. This is a crack in Trump’s base, his core support. Trump won Alabama by nearly 30 points in 2016 but now the state votes for a Democrat.

“The most interesting thing in the polls today is that the voters are split down the middle on whether they still support Trump.

“There is a real division between the Republican establishment and the so-called populist, or Trump-wing of the Republican Party, which is basically a difference by education,” Schneider said.

Moore reportedly did well with voters with less than a college education, while well-educated white voters voted against him in large numbers.

“That split has been true throughout the country. It’s a split in the Republican base; well-educated Republicans don’t like Trump, and they’re beginning to flee the Republican Party,” Schneider said.