For seven nerve-wracking months, they slept through the day in cramped quarters on cold floors, while spending their nights in prayer, keeping fit with dumbbells made from water jugs and peering through the diplomatic compound's curtains for fear of surveillance.

But on Monday, 16 national guardsmen who shocked Venezuela and the world alike by revolting against President Nicolás Maduro were safely out of the country, having successfully fled the Panamanian embassy in Caracas that had been their makeshift home since April.

Venezuelan guardsmen play a game of dominoes inside Panama's embassy, in Caracas, Venezuela, on Nov. 8, 2019. AP

The Associated Press spoke exclusively to the group’s leaders, who provided the first detailed account of what led them to plot with Maduro’s opponents in an uprising that laid bare fraying support for the socialist leader within the armed forces.

Due to security concerns, lieutenant colonels Illich Sánchez and Rafael Soto wouldn’t reveal exactly when or how they left Venezuela. They only said they journeyed in small groups as part of a clandestine “military operation” that counted with the support of dozens of low-ranking troops and their commanders.

“We left Venezuela but our fight to restore Venezuela's democracy will continue,” said Sánchez in a phone interview from an undisclosed location.

The previously untold story of how Sánchez and Soto managed to dupe their superiors and plot a revolt against Maduro underscore how discontent — and fear — is running high inside Venezuela's barracks even as the embattled leader clings to power amid punishing U.S. sanctions imposed after presidential election widely seen as fraudulent.

The two standout officers seemed ideally suited for the high-risk mission, having risen through the ranks to a trusted position with direct control of troops and regular contact with Maduro's top aides.

Sánchez, 41, commanded a garrison of some 500 guardsmen responsible for protecting downtown government buildings including the presidential palace and supreme court. Soto, 43, for a time was assigned to the feared SEBIN intelligence policy, leading a team of some 150 agents charged with spying on government opponents.

Troops loyal to Venezuela's opposition leader Juan Guaido stand outside La Carlota air base in Caracas, Venezuela, on April 30, 2019. Ariana Cubillos / AP file

In their telling, the two longtime friends grew disillusioned watching the devastation of Venezuela's economy and started secretly plotting to remove Maduro. Eventually they teamed up with Maduro’s opponents led by National Assembly President Juan Guaidó, who is recognized as Venezuela’s rightful leader by the U.S. and some 60 countries.

On April 30, they stunned Venezuelans by appearing before dawn with tanks and heavily armed troops on a bridge in eastern Caracas alongside Guaidó and activist Leopoldo López, who they helped spring from what they considered an illegal house arrest.

“When I gathered my troops at 2 a.m. and told them we were going to liberate Venezuela they broke down in tears,” said Sánchez, who as part of his official duties providing security to congress had to speak with opposition lawmakers on a regular basis. “Nobody saw it coming, but they were all immediately committed.”

Adds Soto: “Everything was perfectly lined up for a peaceful transition.”

But they say they were defrauded by Maduro aides, including Supreme Court President Maikel Moreno and Defense Minister Vladimir Padrino, who they claim never fulfilled a promise made to the opposition to abandon their support of Maduro. Both Moreno and Padrino have repeatedly reasserted their loyalty to Maduro.

In the confusing aftermath of the failed rebellion, they scurried for protection on the back of motorcycles, stripping off their olive green fatigues and knocking, unsuccessfully at first, on several embassy doors.

Amid the chaos, López phoned then Panamanian President Juan Carlos Varela, who immediately embraced their cause and arranged their safe entry into the embassy.

He recalled how two months before the U.S. invasion of Panama, in 1989, then-dictator Gen. Manuel Noriega crushed a similar revolt and then ordered the execution of more than 10 ringleaders.

“We couldn’t leave them alone,” Varela said in an interview. “The Sebin was 10 feet from the door. They were going to kill them all.”

The embassy, in an upscale high-rise occupied by state-run companies and well-connected government contractors, would become their makeshift home for the next seven months. Both men said the “humanitarian support” provided by the embassy's staff and the Panamanian people ensured their safety.

While confined, the 16 guardsmen worked hard to maintain their military discipline. To keep out of their host’s way, they adopted an inverted sleep schedule, dozing during the day on thin mattresses strewn across the floor of a small room. Then at night, after the diplomats went home, they’d come alive to cook together on a small stove top, keep fit with dumbbells improvised from 20-liter water bottles and read religious texts in a prayer circle.

Follow NBC Latino on Facebook, Twitter and Instagram.