A former state judge who believes that "God's law" can invalidate federal court decisions won Alabama's Republican primary for U.S. Senate on Tuesday night, sending a clear warning to President Trump and GOP leadership that conservative grass-roots anger will continue to roil the party into the 2018 midterm elections.

Roy Moore, who was twice suspended from his job as the chief justice of the Alabama Supreme Court, defeated incumbent Sen. Luther Strange, who was appointed to the seat vacated by Attorney General Jeff Sessions and was backed by Trump and Senate Majority Leader Mitch McConnell (R-Ky.).

Moore took nearly 55 percent of the vote, rolling over Strange, who pulled in about 45 percent, according to results from Alabama's Secretary of State.

Moore is now the front-runner to win the seat in the Dec. 12 general election. He will face Democratic candidate Doug Jones, a former U.S. attorney in Alabama.

"We have to return the knowledge of God and the Constitution of the United States to the United States Congress," Moore said in his victory speech. "We have become a nation that has distanced ourselves from the very foundation."

In a tweet, Trump quickly threw his support behind Moore: "Congratulations to Roy Moore on his Republican Primary win in Alabama. Luther Strange started way back & ran a good race. Roy, WIN in Dec!"

For conservative opponents of the current Republican leadership, the victory was a godsend — literally, for many — and a validation of the larger effort to replace the current leadership of the Republican Party with a more populist crowd.

"Who's sovereign, the people or the money?" former White House strategist Stephen K. Bannon asked at Moore's victory party in Montgomery. "The people of Alabama just answered: the people."

For McConnell, whose allies committed vast resources to defeat Moore, the loss was the third blow in one day to a man once seen as an unflappable master of political chess.

Earlier Tuesday, McConnell was forced to call off a vote on the latest effort to repeal and replace the Affordable Care Act, his third failed attempt to muster 50 votes in the Senate.

Hours later, Sen. Bob Corker (R-Tenn.), a McConnell ally, announced that he would not seek reelection in 2018, creating another open seat that anti-establishment conservatives are likely to contest. Bannon and other insurgent activists were previously looking to target Republican Senate incumbents in Arizona, Nevada and Mississippi.

On Tuesday, McConnell congratulated a "spirited campaign" that focused on frustration over the lack of progress in Washington.

"I share that frustration and believe that enacting the agenda the American people voted for last November requires us all to work together," McConnell said in a statement.

[Five things to watch in Alabama’s special election]

The defeat of Strange, a 6-foot-9-inch former prosecutor and lobbyist, could also put pressure on Republican Party fundraisers, who are wary of spending money on races they are unlikely to win.

The Senate Leadership Fund, an independent committee allied with McConnell that spent nearly $9 million to elect Strange and attack his rivals, released a statement throwing its support to Moore moments before the race was called. "Judge Roy Moore won this nomination fair and square," said the fund's president, Steven Law.

But there is little hope of a meeting of the minds any time soon. Scott Reed, a political consultant for the U.S. Chamber of Commerce, said Moore's victory was likely to make it harder to pass Trump's agenda, including tax cuts, which will require some conservative compromise to get through the Senate.

"Once again, Bannon's strategy has no logical endgame," Reed said, arguing that the vote count will be harder with Moore in the Senate. "Good luck moving President Trump's growth agenda forward."

With his victory, Moore became the first Republican Senate candidate since the 2014 cycle to overcome a full-scale attack during the primary from allies of Republican leadership and the U.S. Chamber. He also won despite a last-minute push by Trump for Strange that included a barrage of late tweets and a rally Friday in Alabama.

The effect of Strange's loss on Trump is not yet clear, as both candidates in the race draped themselves in the president's "Make America Great Again" slogan. Trump also seemed to distance himself from his own endorsement in the race's final days. At the rally Friday to support Strange, Trump told the crowd, which included many Moore supporters, that he "might have made a mistake." If Moore won the primary, Trump said to applause, "I'm going to be here campaigning like hell for him."

In the final weeks of the campaign, the Chamber spent about $1 million, and the Senate Leadership Fund spent nearly $5 million to support Strange and attack Moore. Republican voters in the state complained of daily direct-mail pieces attacking Moore, and one voter outside Birmingham said Tuesday that he disconnected his home phone to block the barrage of recorded calls.

The local business community, organized by the Chamber, also launched a get-out-the-vote effort among the employees of large companies, including the state's significant federal contracting workforce. And Strange, the Business Council of Alabama argued, was the best person to bring more jobs to the state, which relies heavily on defense contracting.

Unable to match the ad campaign against him, Moore was defended by a loose grouping of anti-establishment conservative activists, including Bannon, former Alaska governor Sarah Palin, "Duck Dynasty" star Phil Robertson and conservative talk radio broadcasters including Laura Ingraham.

But in significant ways, his campaign differed from any other Senate effort in recent memory. On the stump, Moore made his belief in the supremacy of a Christian God over the Constitution the central rallying point of his campaign. His support for stronger immigration laws, less federal spending and a stronger military were all secondary issues.

[Bannon headlines rally for Roy Moore in Alabama runoff]

In three books, Moore has described his legal opinion that the United States was founded as a Christian nation that ultimately answered to the "laws of nature and nature's God," a phrase contained in the Declaration of Independence.

As a judge, Moore refused to obey a federal court order to remove from his courthouse a monument to the Ten Commandments he had installed to underscore his belief. He was removed from his job as a result.

In a 2002 legal opinion, he described homosexual conduct as "an inherent evil," and he has argued that the 2015 U.S. Supreme Court decision that legalized same-sex marriage should not be considered the rule of law. He was suspended from Alabama's court a second time for defying the higher court's marriage decision, and he later decided to retire from the bench.

If elected to the Senate, Moore has promised to be a disruptive force who will directly challenge the leadership of McConnell. Moore plans to crusade against the Senate practice of requiring 60 votes to move most legislation on the Senate floor, which he does not consider constitutional. He has also said he will seek the impeachment of federal judges who defy his view of the Constitution. He has called for military deployment to secure the southern border before the construction of a border wall, and he said he would have opposed the Cassidy-Graham legislation, the most recent effort to repeal the Affordable Care Act, because it was not conservative enough.

Democrats have not yet committed to pouring money into Jones's campaign, but some Republicans, including Trump, have expressed concern that Moore could be vulnerable in the general election. "The people of Alabama deserve a senator who will put aside partisan rancor," Jones said in a statement after Moore's victory.

Alabama politics is historically a rough-and-tumble affair, and the campaign ended much as it began, with Strange playing defense and Moore reveling in his unique approach to public service. After casting his ballot Tuesday morning, Strange awkwardly told reporters he had not heard Trump say at the rally Friday that he may have made a mistake with his endorsement. "The president supports me 100 percent," Strange said.

Moore, who owns several motorized vehicles, decided to ride a horse named Sundance from his property in Gallant, Ala., to the local firehouse to vote Tuesday, taking time to trot back and forth before a group of reporters.

The night before the election, Moore dressed in a cowboy hat and black leather vest at a rally in Fairhope. While giving his speech onstage, he pulled a small handgun from his pocket and pointed at the ceiling to demonstrate his support for the Second Amendment.

[Corker, Republican senator from Tennessee, announces his retirement]

Bannon also appeared at the Monday evening event, along with Robertson and British politician Nigel Farage. "A vote for Judge Roy Moore is a vote for Donald J. Trump," Bannon said, disregarding Trump's endorsement of Strange. "We did not come here to defy Donald Trump."

At polling places across the state Tuesday, voters said they struggled with the conflicting messages in the race. In downtown Montgomery, Mable Greenwood, 58, said she voted for Hillary Clinton in the 2016 election but was now supporting Moore. "The world, I don't think it's going to be here too much longer," she said, explaining her attraction to Moore's religious message. "Everything that the Bible said is going to happen — it is happening."

In Mountain Brook, a Birmingham suburb, a steady stream of voters made their way to Brookwood Baptist Church to cast ballots. Myron Trowbridge, 76, said he was voting for Strange because he could not validate Moore's willingness to flout judicial orders. "I don't respect people who don't respect the law," he said, explaining his reasons for supporting Strange over Moore.

In his concession speech, Strange promised to continue to serve Trump and the state of Alabama for his remaining time in office. "We're dealing with a political environment that I've never had any experience with," he said. "The political seas in this country right now are very hard to navigate, very hard to understand. It's been a very tough deal."

Daniel Teehan in Montgomery and Larry Bleiberg in Birmingham contributed to this report.

Read more at PowerPost