Then in September, on the sidelines of the U.N. General Assembly, Trump discussed it again, this time at greater length, in a private dinner with leaders from four Latin American allies that included Santos, the same three people said and Politico reported in February.

The U.S. official said Trump was specifically briefed not to raise the issue and told it wouldn't play well, but the first thing the president said at the dinner was, "My staff told me not to say this." Trump then went around asking each leader if they were sure they didn't want a military solution, according to the official, who added that each leader told Trump in clear terms they were sure.

Eventually, McMaster would pull aside the president and walk him through the dangers of an invasion, the official said.

Taken together, the behind-the-scenes talks, the extent and details of which have not been previously reported, highlight how Venezuela's political and economic crisis has received top attention under Trump in a way that was unimaginable in the Obama administration. But critics say it also underscores how his "America First" foreign policy at times can seem outright reckless, providing ammunition to America's adversaries.

The White House declined to comment on the private conversations. But a National Security Council spokesman reiterated that the U.S. will consider all options at its disposal to help restore Venezuela's democracy and bring stability. Under Trump's leadership, the U.S., Canada and European Union have levied sanctions on dozens of top Venezuelan officials, including Maduro himself, over allegations of corruption, drug trafficking and human rights abuses. The U.S. has also distributed more than $30 million to help Venezuela's neighbors absorb an influx of more than 1 million migrants who have fled the country.

For Maduro, who has long claimed that the U.S. has military designs on Venezuela and its vast oil reserves, Trump's bellicose talk provided the unpopular leader with an immediate if short-lived boost as he was trying to escape blame for widespread food shortages and hyperinflation. Within days of the president's talk of a military option, Maduro filled the streets of Caracas with loyalists to condemn "Emperor" Trump's belligerence, ordered up nationwide military exercises and threatened with arrest opponents he said were plotting his overthrow with the U.S.

"Mind your own business and solve your own problems, Mr. Trump!" thundered Nicolas Maduro, the president's son, at the government-stacked constituent assembly. "If Venezuela were attacked, the rifles will arrive in New York, Mr. Trump," the younger Maduro said. "We will take the White House."

Even some of the staunchest U.S. allies were begrudgingly forced to side with Maduro in condemning Trump's saber rattling. Santos, a big backer of U.S. attempts to isolate Maduro, said an invasion would have zero support in the region. The Mercosur trade bloc, which includes Brazil and Argentina, issued a statement saying "the only acceptable means of promoting democracy are dialogue and diplomacy" and repudiating "any option that implies the use of force."

But among Venezuela's beleaguered opposition movement, hostility to the idea of a military intervention has slowly eased.

A few weeks after Trump's public comments, Harvard economics professor Ricardo Hausmann, a former Venezuelan planning minister, wrote a syndicated column titled "D Day Venezuela," in which he called for a "coalition of the willing" made up of regional powers and the U.S. to step in and support militarily a government appointed by the opposition-led national assembly.

Mark Feierstein, who oversaw Latin America on the National Security Council during the Obama administration, said that strident U.S. action on Venezuela, however commendable, won't loosen Maduro's grip on power if it's not accompanied by pressure from the streets. However, he thinks Venezuelans have largely been demoralized after a crackdown on protests last year triggered dozens of deaths, and the threat of more repression has forced dozens of opposition leaders into exile.

"People inside and outside the administration know they can ignore plenty of what Trump says," Feierstein, who is now a senior adviser at the Albright Stonebridge Group, said of Trump's talk of military invasion of Venezuela. "The concern is that it raised expectations among Venezuelans, many of whom are waiting for an external actor to save them."