Mr. McCarthy, a golden retriever of a man who hates to be by himself, once cozied up to the president by bringing him a curated jar of his favorite cherry and strawberry Starburst candies. He excels at building the kind of relationships that his allies say will be crucial to leading an effective minority.

“If Kevin McCarthy is alone, does he exist?” joked Representative Patrick T. McHenry, Republican of North Carolina, alluding to the Californian’s uber-social nature. “He thrives on human interaction, and that is his natural sweet spot, and I think this job, the job of minority leader, is a matter of knitting us all together.”

It is common for lawmakers and strategists to preface their remarks about Mr. McCarthy by noting that he is “not a policy guy,” which can double in Washington as a euphemistic put-down, the legislative equivalent of saying that a potential mate has a great personality. There is no denying that Mr. McCarthy, who is known for his encyclopedic knowledge of congressional districts and warm relationships with rank-and-file Republicans, has less interest in the technical details of policy than Mr. Ryan of Wisconsin, who revels in his reputation as an “ideas guy.”

And Mr. McCarthy is not always savvy about how he approaches an issue. When he decided six weeks before the midterm contests to introduce a bill to fully fund Mr. Trump’s border wall over seven years, he neither worked with the White House nor gave advance notice that it was coming, according to two people familiar with the conversations who spoke of condition of anonymity because they were not authorized to comment.

Still, for Republicans licking their wounds from this month’s drubbing and looking toward a grim two years in the minority where they have little ability to influence policy, Mr. McCarthy’s political talents appear to be matched to the moment.

Groomed by Bill Thomas, the former House Ways and Means Committee chairman who represented his Bakersfield district, the bubbly Mr. McCarthy succeeded his more cerebral and irascible boss in 2007 and quickly worked his way up through Republican ranks, rising to the third-ranking position within four years. He was one of the “Young Guns,” a triumvirate of 40-something conservatives including Mr. Ryan and Eric Cantor who styled themselves the future of the Republican Party, and published a book whose cover depicted them all, smiling and impressively coifed, on the balcony of the Capitol.

Mr. Cantor, then the No. 2 Republican, was defeated in a primary in 2014 by Dave Brat, a college professor who harnessed Tea Party discontent to topple him, and Mr. McCarthy slid easily into the job. (Mr. Brat is among the Republicans swept out by Democrats in last week’s elections.) A year later, Mr. Boehner, facing a revolt from the Freedom Caucus, was forced out as speaker. Mr. McCarthy was the presumed heir apparent, but he stumbled over policy pronouncements and infuriated allies by blurting out that a committee investigating the Benghazi attacks was created to sink Hillary Clinton’s popularity. He took himself out of the running.

Now Mr. Ryan, another Young Gun, is retiring, and the lone survivor, Mr. McCarthy, is in line for the top job.