Huber Matos Benitez was an ally of Fidel Castro during the Cuban Revolution but then spent 20 years in prison for treason after he attempted to resign from the regime shortly after the takeover. (Zayra Mo/EPA)

Huber Matos Benitez, who helped lead the Cuban Revolution as one of Fidel Castro’s key lieutenants before his efforts to resign from the burgeoning communist government landed him in prison for 20 years, died Feb. 27 at a hospital in the Miami area. He was 95.

He had a heart attack, his grandson Huber Matos Garsault told the Associated Press.

Mr. Matos was a 34-year-old rice farmer and teacher — and an opponent of Cuban dictator Gen. Fulgencio Batista — when Castro led a failed uprising in 1953. Mr. Matos later joined Castro and served as a commander in the Sierra Maestra mountains.

The two clashed on occasion, but Mr. Matos claimed that at one point Castro named him third in line for leadership after Castro’s brother Raúl and ahead of Ernesto “Che” Guevara, Mr. Matos maintained.

In a May 2009 interview with the AP at his home in Miami, Mr. Matos said he joined the revolution hoping to restore democracy to his country, which the island experienced only briefly before Batista led a coup in 1952. Mr. Matos, who had been a professor of education, first traveled to Costa Rica to obtain weapons and ammunition for delivery to Castro’s forces before eventually joining the rebels in the mountains. He was captured in 1957 by Batista forces but was able to escape, according to his family.

The revolution overthrew Batista on New Year’s Day 1959, and Mr. Matos rolled into Havana at Castro’s side. But within months a disillusioned Mr. Matos wanted out of the new government, fearing the Castros and Guevara were steering the country toward communism, and that Fidel Castro had no intention of holding free elections as he had promised.

“There was another agenda,” Mr. Matos told the AP in 2009. “Fidel said one thing for the public, and the steps he took were another story.”

When he first tried to resign, Castro wouldn’t let him. In October 1959, Mr. Matos was arrested and convicted of treason. He was told he would face the firing squad but believes he was sent to prison instead because Castro feared he would become a martyr.

In his book, “How Night Fell,” Mr. Matos described being tortured and kept for years in isolation. He was released in October 1979 and was reunited with his wife and four grown children. He initially lived in Caracas, Venezuela, where he founded the group Independent and Democratic Cuba, and later moved to Miami.

“The revolution didn’t have to become a catastrophe,” Mr. Matos said. “If [Castro] would have brought reforms within the democratic framework, Cuba would have been a great country.”

Mr. Matos lauded his wife for her bravery during the years he spent behind bars, noting that she worked as a seamstress and raised their four children while keeping his case alive in the international human rights community.

In Miami, Mr. Matos led the Independent and Democratic Cuba group, one of many anti-Castro organizations. He was regarded with suspicion by some of the Miami exile community’s most powerful members because of his early opposition to Batista and his support for dissidents inside Cuba. Still, Mr. Matos remained an outspoken critic of Castro. Fearing assassination attempts, he often kept a pistol in a leather holster tucked into his waistband.

In May 2009, at age 90, Mr. Matos traveled to Honduras to protest a proposal to reinstate Cuba as a member of the Organization of American States.

“I’m one of those who’s convinced that there will be a change in Cuba in a time not very far in the future; that’s inevitable,” he said. “The system failed completely. It not only failed completely, but among the young generations there’s an eagerness for change that’s unstoppable.”