Chagrined about Mr. Trump, Republicans, in particular, have been increasingly dropping Mr. Johnson’s name when faced with voting for Mr. Trump or Mrs. Clinton.

“I would probably check the box for Gary Johnson, or write in James Madison,” Tim Miller, a former spokesman for Jeb Bush who is spearheading the Stop Trump movement, said last week.

Mr. Johnson does not have the Libertarian nomination locked up, but he is widely considered the front-runner ahead of his party’s Memorial Day weekend convention. His opponents include Austin Petersen, the founder of The Libertarian Republic magazine, and John McAfee, who made his fortune developing antivirus computer software and as recently as 2012 was hiding from the Belize police after being sought for questioning in the death of his neighbor.

During a Libertarian forum broadcast on Fox Business Network on Friday night, the three candidates debated issues such as whether a Jewish baker should be required to bake a Nazi wedding cake and pondered questions such as “What is a drug?” and “Why do we have war?” Mr. McAfee assured voters that he had never been charged with murdering his neighbor, and Mr. Petersen argued that all foreign aid should be stopped.

Although Mr. Johnson is turned off by many of Mr. Trump’s policies, he says he can understand the Manhattan businessman’s appeal. When running for governor of New Mexico in the 1990s as a Republican, Mr. Johnson used his success as an entrepreneur in the construction industry to make the case that he could bring real-world common sense to state government. He won, serving two terms from 1995 to 2003 and vetoing more than 700 bills.

More recently, Mr. Johnson was the chief executive of Cannabis Sativa, a company that develops new marijuana products. He quit that job to run for president this year but still uses marijuana recreationally and says it should be legalized.