The Republican Governors Association and a number of high-level party operatives counseled Mr. Trump against siding with Mr. Kobach, because polls show he is unpopular with the general electorate in Kansas and would provide Democrats an opening to take back the governorship. But Mr. Trump has grown fond of his king-making abilities after weeks of successfully intervening for candidates who went on to win Republican nominating contests from South Carolina to Georgia to Alabama.

Further, Mr. Kobach was an early and loyal supporter of Mr. Trump, endorsing him shortly before Kansas’ presidential nominating caucus, and has developed a rapport with the president’s eldest son, Donald Trump, Jr. And he served earlier this year as a member of the administration’s short-lived voter integrity commission.

[Read about how Kris Kobach built a national profile.]

Mr. Trump telephoned some of his political advisers Monday morning to raise the possibility of getting behind Mr. Kobach, according to a Republican official familiar with the call. They relayed to him that if the party nominated a firebrand like Mr. Kobach for governor, it could have a ripple effect in the House, energizing Democrats in a pair of competitive Kansas congressional races. But Mr. Trump indicated he felt an abiding loyalty to Mr. Kobach and wanted to help an ally, the official said.

West Wing aides had hoped to keep the Kansas race away from Mr. Trump’s line of sight, but were uneasy about what he may do during an extended, and unsupervised, trip to his New Jersey golf resort. And that is where the president unfurled his endorsement, blindsiding the governors association and Mr. Colyer, who just a few days ago praised the president in an interview, and made the case for why he should not side with Mr. Kobach.

Mr. Kobach said in a telephone interview that he had spoken to Mr. Trump on Saturday but that he did not know the endorsement would be coming until he got a call from the president’s aides Monday morning. “He makes a big splash at a critical time,” Mr. Kobach said with evident delight, noting that he would be adding the endorsement to last-minute digital advertising and including it in scripts for get-out-the-vote calls.