President-elect Donald Trump was three weeks into his search for a secretary of state when former Defense Secretary Robert Gates arrived at his New York office for a private talk.

The cabinet selection was bedeviling Mr. Trump. His first instinct to pick a loyal insider was undercut by reports of the prospective nominee’s overseas money-making ventures, and his flirtation with a known political adversary was being hammered by his own supporters. What if, he asked Mr. Gates, he wiped the slate clean and started over?

The...