Mr. Kobach, who has spent years building a national profile, is a brash, outspoken ally of the president whose campaign rhetoric sometimes sounds like Mr. Trump’s and who has long excited the party’s base. Mr. Colyer, more measured in his speech and not known as well outside Kansas, was seen by many national Republicans as a safer general election candidate with more appeal to moderate voters.

Though Republicans are dominant in Kansas politics, Democrats are energized and could benefit from the other side’s prolonged primary squabble. State Senator Laura Kelly, the Democratic nominee, and Greg Orman, a businessman running as an independent, will face Mr. Kobach in November.

In a statement on Tuesday night, Ms. Kelly compared Mr. Kobach to Sam Brownback, the former Kansas governor whose conservative tax-cutting policies led to revenue shortfalls and significant budget cuts. Mr. Brownback, who was deeply unpopular by the end of his tenure, resigned early this year to become an ambassador.

“With Kris Kobach as governor, Kansans get all of the failed policies of Sam Brownback plus Kobach’s unique brand of hyper-partisanship and self-promotion,” Ms. Kelly said.

Though Mr. Kobach and Mr. Colyer had each acknowledged their race was too close to call after the initial count ended with a 191-vote margin, the days that followed brought increasing acrimony. Despite platitudes about party unity, the tone grew harsher after one rural county discovered a tabulation error that added 100 votes to Mr. Colyer’s tally.

In recent days, Mr. Colyer warned that many political independents had been given faulty information at the polls and that their ballots may be improperly discarded. He also started a “voting integrity hotline” and accused Mr. Kobach, in his role as secretary of state, of providing bad advice to county election officials.