BOGOTA, Colombia — As a meeting last August in the Oval Office to discuss sanctions on Venezuela was concluding, President Trump turned to his top aides and asked an unsettling question: With a fast unraveling Venezuela threatening regional security, why can't the U.S. just simply invade the troubled country?

The suggestion stunned those present at the meeting, including U.S. Secretary of State Rex Tillerson and national security adviser H.R. McMaster, both of whom have since left the administration. This account of the previously undisclosed conversation, as reported by The Associated Press, comes from a senior administration official familiar with what was said.

In an exchange that lasted around five minutes, McMaster and others took turns explaining to Mr. Trump how military action could backfire and risk losing hard-won support among Latin American governments to punish President Nicolas Maduro for taking Venezuela down the path of dictatorship, according to the official. The official spoke to The Associated Press on the condition of anonymity because of the sensitive nature of the discussions.

Get Breaking News Delivered to Your Inbox

But Mr. Trump pushed back. Although he gave no indication he was about to order up military plans, he pointed to what he considered past cases of successful gunboat diplomacy in the region, according to the official, like the invasions of Panama and Grenada in the 1980s.

The idea, despite his aides' best attempts to shoot it down, would nonetheless persist in the president's head.

The next day, Aug. 11, Mr. Trump alarmed friends and foes alike with talk of a "military option" to remove Maduro from power. The public remarks were initially dismissed in U.S. policy circles as the sort of martial bluster people have come to expect from the reality TV star turned commander in chief.

But shortly afterward, he raised the issue with Colombian President Juan Manuel Santos, according to the U.S. official. Two high-ranking Colombian officials who spoke on condition of anonymity to avoid antagonizing Mr. Trump confirmed the report.

Then in September, on the sidelines of the U.N. General Assembly, Mr. 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 Mr. 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." Mr. 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 Mr. 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 Mr. 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 Mr. 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, Mr. 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, 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, 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 Mr. 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 Mr. 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 Mr. 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."