Daniel Cameron, Kentucky’s attorney general and a close ally of Senator Mitch McConnell, clinched the state’s Republican nomination for governor on Tuesday, according to The Associated Press, fending off a spirited and costly challenge by Kelly Craft, a wealthy former ambassador to the United Nations.

Mr. Cameron’s double-digit victory sets up what is likely to be the most closely watched and fiercely contested statewide race remaining in 2023. Gov. Andy Beshear, a Democrat running for re-election, is one of the most popular governors in the country, and even Republicans believe he will be difficult to beat in November.

The result on Tuesday also served as a setback for Gov. Ron DeSantis of Florida as he nears an expected presidential campaign. On Monday, he had endorsed Ms. Craft, abruptly turning the race into a proxy battle between himself and former President Donald J. Trump, who backed Mr. Cameron in June 2022.

In his victory speech on Tuesday night, Mr. Cameron said, “The Trump culture of winning is alive and well in Kentucky” — a pointed jab at Mr. DeSantis’s recent remarks criticizing the Republican Party’s “culture of losing.”

With more than 90 percent of the vote counted, Ms. Craft, who belongs to one of the biggest Republican megadonor families in the country, trailed Mr. Cameron by roughly 30 percentage points. She was also behind a third candidate, Ryan Quarles, Kentucky’s agricultural commissioner.

Republicans have long viewed Mr. Cameron as a potential political star who could join the next generation of the party’s leaders. Mr. Cameron has had a trailblazing career — he was the first Black man to be elected attorney general in Kentucky and the first Republican elected to the post in 50 years — and his campaign is likely to draw the support of operatives and donors beyond Kentucky.

Mr. Cameron turned to the general election in his victory speech. “The new religion of the left casts doubt on the greatness of America,” he said. “They embrace a picture of this country and this commonwealth that is rooted in division, that is hostile to faith and that is committed to the erosion of our education system.”

And he took aim at his November opponent: “Andy Beshear is resigned to live in a commonwealth where violent crime is high and the work-force participation rate is low. He’s content to preside over the abandonment of our inner cities and the desolation of our rural communities.”

Part of Mr. Beshear’s strength stems from Republicans’ dominance of the state. The party holds supermajorities in the Legislature, making it difficult for the governor to wield much power without a veto. Yet that dynamic has allowed Mr. Beshear to avoid contentious showdowns with Republicans on hot-button issues and has let him focus on using state resources to help repair infrastructure and improve the economy.

Mr. Beshear, who coasted in his primary on Tuesday, remained mostly quiet during the Republicans’ battle, running a scaled-down digital ad campaign centered on his record of expanding voting rights and presiding over economic expansion in the state.

“I’m honored to be your Democratic nominee for governor, Kentucky,” Mr. Beshear wrote on Twitter on Tuesday night. “Together, we’re going to continue to build on the progress of the past 3 years — moving our commonwealth not left or right, but forward. Let’s do this.”

And in his victory speech, Mr. Beshear sought to project an uplifting tone, and said the Republican candidates presented a stark contrast from himself. “They’re trying to pit us against each other,” he said, “calling anybody who disagrees with them names, telling you it’s OK to yell, even hate your fellow human being. We are so much stronger than that.”

Though Mr. Cameron was elected as Kentucky’s attorney general in 2019, he fully arrived on the national scene with a prime-time address during the 2020 Republican National Convention.

He immediately became a favorite of Mr. Trump, who endorsed his campaign nearly a year before the primary election. Mr. Cameron made Mr. Trump’s support central to his campaign to lead Kentucky, which the former president carried by more than 25 percentage points in 2020.

Mr. Cameron’s tenure as attorney general has included numerous clashes with the federal government. They include his fighting vaccine requirements for federal contractors and trying to stop the Biden administration from allowing the lapse of Title 42, the Covid-era Trump immigration policy that ended on Thursday. He has also brought lawsuits against Mr. Beshear, including seeking new limits to abortion access.

These legal tussles became a cornerstone of his stump speech.

“When Governor Beshear decided to shut down churches, I went into federal court and, after nine days, got churches reopened in Kentucky,” Mr. Cameron said at a campaign stop in Shepherdsville last month, referring to early pandemic regulations.

Mr. Cameron, a former aide to Mr. McConnell, was expected to cruise to the nomination on the back of his ties to the powerful Senate minority leader and to Mr. Trump. But the race tightened after Ms. Craft, who is married to a coal billionaire, Joe Craft, began pouring millions of her own money into the race, flooding the airwaves with ads. Mr. Cameron did not have the resources to keep pace.

The bruising nature of the primary raised worries among some Kentucky Republicans about their prospects in the general election.

For nearly two months, Ms. Craft was the only major candidate with ads from her or her allies on broadcast television. Combined, she and her allies spent more than $7 million on advertising, compared with just $2.6 million by Mr. Cameron and his supporters, according to AdImpact, an ad-tracking firm.

Her campaign attacked Mr. Cameron for supporting the closure of a coal plant (the coal plant in question was in West Virginia) and rebuked him for not fighting the Justice Department’s investigation into the Louisville Police Department after police officers shot and killed Breonna Taylor during a botched raid on her apartment in 2020. She also sought to paint Mr. Cameron as a “follower” of Mr. McConnell, a rare public dig at a man who has guided Kentucky politics for nearly 40 years.

Mr. Cameron received a late boost from an allied political action committee, Bluegrass Freedom Action, which received most of its funding from the Concord Fund, which is part of a network of influential conservative groups managed by the activist Leonard A. Leo. The group spent $2.1 million in the final six weeks of the primary, aiding Mr. Cameron and attacking Ms. Craft.

A special election in a district that could have flipped the State House to the Republicans instead stayed in Democratic hands, according to The Associated Press.

Top Democrats, led by President Biden and Gov. Josh Shapiro, had urged voters to mobilize for Heather Boyd, the party’s candidate in the three-person race. They had framed the election as crucial to protecting reproductive rights in Pennsylvania, saying that Republicans would seek to use their legislative majority to bypass the governor’s veto power by placing an abortion ban amendment on the ballot for voters to decide.

Ms. Boyd, a former legislative aide and onetime teacher, beat Katie Ford, a Republican who was a combat medic for the U.S. Army Reserve and also has an education background.

Mr. Shapiro hailed the result in a post on Twitter. “Heather Boyd is a teacher, mom, and public servant — now, she’s Delaware County’s newest state rep.,” he wrote. “Together, we’ll work to get things done for Pennsylvanians and protect real freedom. And to Delco: Thank you for showing up to defend our rights and the Democratic House majority.”

The special election, in the 163rd Legislative District in southeast Delaware County, was prompted by the March resignation of Mike Zabel, a Democrat who was accused of harassment.

In another special State House election on Tuesday, Republicans maintained power in the 108th Legislative District in north-central Pennsylvania as Michael Stender, a Republican school board member and a firefighter, was victorious in a three-candidate race, according to The A.P.

The safe G.O.P. seat opened up this year when Lynda Schlegel Culver, the longtime incumbent, resigned after winning a vacant seat in the State Senate.

Donna Deegan, a Democrat, won a runoff for the mayor’s office in Jacksonville, Fla., beating Daniel Davis, a Republican backed by Mr. DeSantis. Mr. Davis conceded the race on Tuesday evening.

Ms. Deegan will be the first woman to lead her city as mayor. “We made history tonight,” she said in her victory speech. “It is a brand-new day for Jacksonville, Florida.”

Neil Vigdor contributed reporting.