HOMEWOOD, Ala. — Roy S. Moore, a former chief justice of the State Supreme Court, and Senator Luther Strange emerged from a crowded Republican field on Tuesday in a special Senate primary in Alabama, according to The Associated Press. They will face off for their party’s nomination next month in a runoff election, a contest that will test President Trump’s clout in a deeply conservative state.

Neither Mr. Strange, 64, backed by Mr. Trump and millions of dollars in spending by outside groups, nor Mr. Moore, 70, a favorite of evangelical voters, received more than 50 percent of the vote in a race that evolved into seeing who could embrace Mr. Trump more when the leading contenders were closely aligned on policy.

But Mr. Moore significantly outpolled Mr. Strange, taking 39.6 percent of the vote to the senator’s 32.1 percent, with 91 percent of precincts reporting as of 11:35 p.m. Eastern time. Representative Mo Brooks, a hard-line conservative, finished third with 19.8 percent of the vote.

Taking the stage after it became clear he and Mr. Strange would enter the runoff, Mr. Moore predicted a wave of “the most negative campaign ads in the history of Alabama,” and he leveled sharp attacks against Republican leaders. Tuesday’s results, he said, showed that “the attempt by the silk-stockinged Washington elitists to control the vote of the people of Alabama has failed.”

But on a night when Mr. Moore antagonized officials in Washington, he also appealed to the religious fervor that has been central to his political appeal.

“Without God, we will never return to the greatness we were meant to have,” Mr. Moore told a crowd of supporters in Montgomery, just down Dexter Avenue from the courthouse where he once presided. “We must be good again before we can be great.”

Mr. Strange, appointed this year to fill the seat vacated by Attorney General Jeff Sessions, appeared to pick up some momentum from Mr. Trump’s support. He now faces a six-week sprint in which his prospects will be determined in large part by how many more voters Mr. Trump can swing his way.

Appearing in this affluent Birmingham suburb, Mr. Strange, invoking his college basketball career, told a well-tailored group of supporters that he was eager to compete “one on one.”

And he offered a preview of his message for the runoff by repeatedly highlighting Mr. Trump’s support and borrowing his slogan.

“What it all boils down to is: Who’s best suited to stand with the people of this country, with our president, and make sure we make America great again?”

Throughout the campaign, Mr. Brooks, a member of the House Freedom Caucus from northern Alabama, fiercely attacked Mr. Strange over his appointment by a now-disgraced governor and his links to a Washington party establishment that underwrote much of his campaign. But Mr. Brooks’s voters loom as the most pivotal constituency up for grabs in the Sept. 26 runoff.

Appearing at his election night party in Huntsville, Mr. Brooks, who was hit hard by Mr. Strange’s Washington allies, declined to endorse either of the remaining candidates but did notably say that Mr. Moore had run an “honorable” campaign.

The runoff will effectively hinge on what Alabama Republicans are more uneasy with: Mr. Strange, an appointed senator many believe has been foisted upon them by state and national party insiders, or Mr. Moore, a highly controversial jurist who was once taken off the bench after he refused to remove a Ten Commandments monument from the Supreme Court building.

Mr. Trump is expected to campaign in the state for Mr. Strange, and outside Republican groups are already preparing to attack the lightly funded Mr. Moore with a negative ad campaign. Alabama Democrats — who tapped Doug Jones, 63, a former United States attorney in Birmingham, as their nominee on Tuesday — will be watching the Republican race closely and may get national help should Mr. Moore emerge as the Republican standard-bearer.

Utah Republicans went to the polls on Tuesday to nominate a candidate for the special election to replace former Representative Jason Chaffetz, who resigned this summer. John Curtis, mayor of Provo, Utah, emerged as the winner, according to The Associated Press.

In Alabama, this rare, off-year summer primary was hardly a coronation. With the Democratic Party greatly diminished here, the most intense competition now takes place within a Republican Party divided by factions and deeply personal feuds. The Senate contest showcased, in bitter and public ways, the suspicions that many Republicans harbor toward one another and the lingering fallout from a scandal involving the governor.

The race was an unexpected one: Until Mr. Trump’s election last year, few would have thought that Mr. Sessions would leave the Senate anytime soon. But when Mr. Trump picked him for a cabinet position, the matter of Mr. Sessions’s seat immediately became controversial.

In February, Robert Bentley, then the governor, appointed Mr. Strange, at the time Alabama’s attorney general, while Mr. Strange was running an investigation into Mr. Bentley’s relationship with a close aide.

Speculation swirled in Montgomery, Alabama’s capital, and around the state about the specter of a corrupt bargain between Mr. Bentley and Mr. Strange, who many in Alabama believed aspired to higher office. Both men denied any wrongdoing, but Mr. Bentley remained a political liability to Mr. Strange, especially after he pleaded guilty to two misdemeanors and resigned in April.

Also complicating matters for Mr. Strange was the grass-roots anger toward Washington Republicans for not repealing the Affordable Care Act, a fury increasingly being taken out on Mitch McConnell, the Senate majority leader.

“There’s a tremendous amount of frustration,” Mr. Strange acknowledged in an interview on Monday.

Yet it fell to Mr. McConnell and his allies to shore up Mr. Strange, a striking turn of events for a man who had already won two statewide general elections and is known by the nickname Big Luther, in homage to his 6-foot-9 stature.

Money tied to Mr. McConnell fueled an onslaught of advertising, and Alabama endured a saturation of television commercials. Mr. Brooks bore the brunt of the attack ads, most of them highlighting his criticism of Mr. Trump during last year’s campaign, and lashed out at Mr. Strange and Mr. McConnell.

Last week, Mr. Trump sent out the much-coveted endorsement for the senator on Twitter. He followed up on Monday morning: “Luther Strange of the Great State of Alabama has my endorsement. He is strong on Border & Wall, the military, tax cuts & law enforcement.” He also recorded a get-out-the-vote phone call on Mr. Strange’s behalf, and, on Tuesday morning, again posted on Twitter to promote Mr. Strange.

The endorsement, a political gift from the president to Mr. McConnell even as Mr. Trump assailed the majority leader’s handling of a repeal of the Affordable Care Act, appeared to help Mr. Strange with some voters, but it still left many Alabama conservatives unhappy. Mr. Brooks openly wondered whether Mr. Trump was “getting bad advice” or whether “the White House has taken a hard left turn toward the establishment wing of the Republican Party and abandoned many of the conservative principles that helped him get elected.” Mr. Moore, who rode a horse named Sassy to the polls on Tuesday, was similarly frustrated.

Outside a polling place in Auburn, voters on Tuesday repeatedly described their disgust with Republican officials in Washington and made plain that Mr. Trump’s endorsement had not swayed them.

“Why irritate — my God, it looks like 60, 70, 80 percent — of the Alabama population?” asked James Cox, a lawyer, referring to the sizable number of Republicans who polls said were skeptical of Mr. Strange. “Why alienate 80 percent in a campaign that you’re going to have a Republican senator?”

Frustrated by how Mr. Strange was appointed to the Senate, he voted for Mr. Brooks.

“He’s about as exciting as a wet noodle, but he’s consistently conservative,” Mr. Cox said. “Could he do a better job? Yeah, I suspect most of them could do a better job, but at least he doesn’t scare me right now.”

Although Mr. Brooks, Mr. Moore and Mr. Strange were the leading contenders, some Republicans said they were unsatisfied with even those choices.

“Luther Strange, I wouldn’t vote for him,” Bruce Hill, 62, said. “Judge Moore, I wouldn’t vote for him if he’d come in third in a two-horse race, and Mo Brooks is the same damn way.”

A version of this article appears in print on , on Page A17 of the New York edition with the headline: 2 G.O.P. Candidates, One Backed by Trump, Head to Runoff in Alabama Senate Race. Order Reprints | Today’s Paper | Subscribe