MONTGOMERY, Ala. — Roy S. Moore, a firebrand former chief justice of the Alabama Supreme Court, overcame efforts by top Republicans to rescue his rival, Senator Luther Strange, soundly defeating him on Tuesday in a special primary runoff.
The outcome in the closely watched Senate race dealt a humbling blow to President Trump and other party leaders days after the president pleaded with voters in the state to back Mr. Strange.
Propelled by the stalwart support of his fellow evangelical Christians, Mr. Moore survived an advertising onslaught of more than $10 million financed by allies of Senator Mitch McConnell, the majority leader. His victory demonstrated in stark terms the limits of Mr. Trump’s clout.
Taking the stage after a solo rendition of “How Great Thou Art,” an exultant Mr. Moore said he had “never prayed to win this campaign,” only putting his political fate “in the hands of the Almighty.”
“Together, we can make America great,” he said, borrowing Mr. Trump’s slogan and adding, “Don’t let anybody in the press think that because he supported my opponent that I do not support him.”
Mr. Trump had tweeted his support for Mr. Strange several times in recent days, but tweets appeared to be deleted on Tuesday night. Mr. Trump offered congratulations to Mr. Moore in a tweet. “Luther Strange started way back & ran a good race. Roy, WIN in Dec!” he wrote.
In a race that began as something of a political afterthought and ended up showcasing the right’s enduring divisions, the victory by Mr. Moore, one of the most tenacious figures in Alabama politics, will likely embolden other anti-establishment conservatives to challenge incumbent Republicans in next year’s midterm elections.
And more immediately, the party will be forced to wrestle with how to prop up an often-inflammatory candidate given to provocative remarks on same-sex marriage and race — all to protect a seat in a deep-red state. Mr. Moore’s incendiary rhetoric will also oblige others in the party to answer for his comments, perhaps for years to come, at a time when many Republicans would just as soon move on from the debate over gay rights.
On Dec. 12, Mr. Moore will face Doug Jones, a former federal prosecutor and the Democratic nominee, in a race that will test the party loyalties of center-right voters who may be uneasy about their nominee. It may also reveal just how reliably Republican the state has become in the quarter-century since a Democrat last won a Senate election here.
Mr. Jones said in an interview Tuesday afternoon that he believed voters would reward a candidate focused on “kitchen-table issues,” and said Alabama’s public reputation was at stake in the election. “People are tired of being embarrassed in this state,” Mr. Jones said. “People want to see someone who can get things done.”
But Mr. Moore, 70, has proved himself to be a political survivor. He has been effectively removed from the State Supreme Court twice — the first in 2003, over his refusal to remove a statue of the Ten Commandments in the courthouse; the second last year, when he urged the state’s probate judges to defy federal orders regarding same-sex marriage.
And in recent days, both the president and Vice President Mike Pence had campaigned for Mr. Strange. Mr. Trump, an enormously popular figure in Alabama, cast aside the tradition of presidents treading carefully in contested primaries, as well as the warnings from his own advisers regarding a candidate trailing in the polls.
Yet instead of delivering a tightly crafted testimonial at a rally on Friday, the president rambled for nearly an hour and a half about a range of topics, while openly questioning whether he was making a mistake coming into the state for Mr. Strange, who oriented his entire run around Mr. Trump’s endorsement and stood looking on with a red “Make America Great Again” hat atop his head.
Mr. Strange conceded defeat on Tuesday night before a subdued audience at a hotel outside of Birmingham, acknowledging in a moment of striking candor that he did not fully grasp the forces at play in his loss.
“We’re dealing with a political environment that I’ve never had any experience with,” Mr. Strange said. “The political seas, the political winds in this country right now are very hard to navigate. They’re very hard to understand.”
He thanked Mr. Trump effusively, praising the president as a “loyal friend” and attempting to absolve him of any blame for the result. “If this causes him any trouble,” Mr. Strange said, “it’s not his fault.”
Mr. Strange’s defeat was the first time an incumbent senator with active White House support has lost since 2010, when Arlen Specter, the longtime senator of Pennsylvania, was beaten in a Democratic primary after switching parties.
But his loss was not just a blow to Mr. Trump. Mr. Moore relentlessly linked the senator to Mr. McConnell, who has made a priority of protecting his caucus from intraparty challenges, but is an increasingly polarizing figure among grass-roots Republicans. Despite the money and staff he directed to the race, Mr. McConnell became as much a liability as he was an asset, leaving Republicans nervously wondering what that may portend in other primaries next year.
On Tuesday night, Mr. McConnell said in a statement that he understood Mr. Moore had channeled “a dissatisfaction with the progress made in Washington.” Saying that he shared that frustration, Mr. McConnell said he was determined to help Mr. Moore win, and made no references to the bitter attacks on his leadership by Mr. Moore and his allies.
Mr. McConnell and his allies were jolted with another reminder of their limited control earlier in the day, when Senator Bob Corker of Tennessee, a popular incumbent, announced he would not run for re-election. As the first senator to opt out of seeking another term in 2018, Mr. Corker opened the way for another rowdy Southern primary in which the national party’s influence may be sorely tested.
Stephen K. Bannon, an ousted White House adviser and an enthusiastic backer of Mr. Moore, crowed about Mr. Corker’s retirement in brief remarks before Mr. Moore took the stage on Tuesday night. Mr. Bannon predicted a populist “revolution” would follow the Alabama results.
Mr. Strange’s demise was in some respects as much a local phenomenon as a national one, stemming from his appointment this year by then-Gov. Robert Bentley to fill the seat vacated by Attorney General Jeff Sessions. Mr. Strange, the state’s attorney general at the time, was overseeing an investigation into Mr. Bentley’s personal relationship with a close aide, suggesting to many in a scandal-weary state that there may have been a corrupt bargain. The newly appointed senator denied any wrongdoing, but never fully confronted the issue in a way that would eliminate the lingering cloud over the appointment.
And by Monday, an adviser to Mr. McConnell, anticipating defeat, started to privately make the case that it was Mr. Bentley’s scandal and the circumstances around the appointment that was most to blame for Mr. Strange’s lackluster support.
Mr. Strange’s status as a proxy for the Republican establishment and a test of the president’s sway came about almost by accident — a consequence of factors having little to do with Mr. Strange himself.
The Senate Republican leader treated Mr. Strange as the political equal of his elected colleagues and ordered strategists in Washington not to work against him. Mr. McConnell and a host of other senators lobbied an initially reluctant Mr. Trump to get involved on Mr. Strange’s behalf over the objections of some advisers. The confusing crosscurrents of the party were on vivid display when the president campaigned for Mr. Strange on Friday.
As staff members from the party’s campaign arm allied with Mr. McConnell looked on, Mr. Strange told the conservative audience that they should elect him so he could “stand up to” Mr. McConnell.
And then the president took the stage and assured attendees he would back Mr. Moore were Mr. Strange to lose, comments that were soon made into an online ad by an anti-establishment conservative group.
Mr. Strange made little attempt to find a new, more moderate universe of voters in the runoff who would recoil from the thought of Mr. Moore as their senator, a strategy fashioned next door in Mississippi when Senator Thad Cochran found himself in a runoff with a hard-line primary challenger in 2014. In fact, some strategists who had been with Mr. Cochran’s campaign said they did not hear from Mr. Strange’s advisers.
The perils of presidential involvement were obvious to some, and conservative allies of Mr. Trump, including Mr. Bannon, had counseled him not to meddle in Alabama.
But he was not the only prominent figure here to gamble on Mr. Strange. Senator Richard Shelby, a pillar of Alabama politics for over 45 years, dispensed with his usual caution to support a longtime friend. But he saw how the political winds were blowing well before Tuesday.
On a get-out-the-vote conference call with Mr. Strange’s supporters this month, he recounted an anecdote about the 1970 Democratic governor’s race here between Albert Brewer, a racial moderate, and the segregationist George C. Wallace, a divisive figure in his time. After it became clear that Mr. Wallace had won, the University of Alabama’s young, progressive president, F. David Mathews, mournfully turned to his family and said they would have to “get used to living with George Wallace.”
Now, Mr. Shelby said, they may have to get used to living with Mr. Moore in the Senate, where he could be just as divisive.