BIRMINGHAM, Ala. (AP) — Democrat Doug Jones has won election to the U.S. Senate from Alabama, dealing a political blow to President Donald Trump.

Jones has defeated Republican Roy Moore, a one-time GOP pariah who was embraced by the Republican Party and the president even after facing allegations of sexual impropriety.

Getty Images

An attorney and former prosecutor, Jones rallied voters on a message of moving past the Moore controversies. He was buoyed by an influx of national Democratic cash and endorsements.

Jones' victory is set to narrow the slim Republican majority over Democrats in the Senate to 51-49. His win in the Republican stronghold energizes the Democratic Party as it looks to build on anti-Trump sentiment to mount a challenge next year to Republican control of Congress.

Earlier Tuesday evening, Moore briefly greeted an optimistic crowd at his election night party in Montgomery.

Moore shook hands with supporters after they chanted, "Judge Roy Moore." He then left to watch returns in another room.

Moore had looked for support in rural areas and party loyalty from Republicans to carry him to victory.

As he's done in past elections, Moore rode his horse to the polls to cast his ballot in the race.

He was accompanied by his wife Kayla Moore, also on horseback, as he voted at a rural fire station in the northeast Alabama community of Gallant.

Moore spoke briefly to reporters, talking in generalities and not discussing allegations that he sexually molested teenage girls decades ago.

Jones, meantime, has become the first Alabama Democrat elected to the U.S. Senate in 25 years.

President Donald Trump and the Republican National Committee broke with top congressional leaders in standing by Moore despite the accusations, wagering that maintaining the seat in the Republican stronghold was of paramount importance.

With the win, Democrats break their 0-5 streak in special elections for Republican-held seats in 2017, and are looking for momentum heading into the 2018 midterm elections.