But that story line never broke through. In fact, the race spotlighted growing divisions between establishment Republicans personified by Mr. McConnell and his allies and Trump Republicans, even though it was Mr. Strange who had the president’s endorsement.

The gap was so wide that when Mr. Trump campaigned for Mr. Strange, he tried to distance the senator from the Republican leader.

“They say he’s friendly with Mitch — he doesn’t even know Mitch McConnell,” Mr. Trump told a raucous crowd of several thousand people.

That was not quite true. The Senate Leadership Fund, a “super PAC” that Mr. McConnell helped found, spent nearly $9 million trying to elect Mr. Strange, said Steven Law, its president and chief executive. Mr. Law, like Mr. Holmes, attributed the outcome of the campaign to “dissatisfaction with the sluggish pace of change in Washington,” adding that “Republican primary voters are just as angry in 2017 as they were in 2016.”

With Democrats across the country energized by the election of Mr. Trump, some analysts say Democrats now have an outside chance to pick up the seat — even in a deeply conservative state like Alabama. But if Mr. Moore wins, he will almost certainly be a wild card in the Senate, where Mr. McConnell is already struggling to keep the 52 Republicans in line.

“The stakes here are high,” said Scott Jennings, a Republican strategist who is close to Mr. McConnell. “His majority of 52 is slim, and it’s even slimmer when you consider at any given time there are four to six of them who are contrarians. So if you take out a Luther, who is not a contrarian, and you throw in a Roy Moore, who’s going to be a contrarian, that makes the majority even less effective and productive.”