Roy S. Moore, a former chief justice of the Alabama Supreme Court, spoke after defeating Senator Luther Strange in Montgomery, Ala., on Tuesday.

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.”

Mr. Strange with his wife, Melissa, in Birmingham, Ala., on Tuesday.

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…