When the Brazilian friar Frei Betto met Fidel Castro in 1980 in the Nicaraguan capital of Managua, the two had a dense conversation about religious freedom in Cuba that led to a bestselling book that helped pave the way for a church-state rapprochement, and eventually, the visit by Pope John Paul II.

That book laid bare Fidel’s complex relationship with the Catholic faith of his childhood in 1940s Cuba, where as a child he was educated by Spanish Jesuit priests at an elite private school in the island’s southern city, Santiago.

Betto, a liberationist Dominican sympathetic to the Cuban revolution, told Castro in Managua that his communist state had, in effect, three options. It could be hostile to the Catholic Church — in which case it simply made the case for the U.S. embargo —  indifferent to it, or in dialogue with it along with other churches and faiths.

Castro accepted that the third option was the right one, and admitted that he hadn’t met a Catholic bishop in 16 years. While the revolutionary government had never broken with the Holy See, it was, in effect, a confessional state — officially atheist.

In the course of the 1980s, Castro moved the revolution slowly towards recognizing the Catholic Church’s presence in Cuba, meeting with bishops, and allowing, if not religious freedom, then at least freedom of worship.

When Betto in 1985 published his Fidel y la Religión, it went on to sell 1.3m copies in Cuba alone, and helped create a new conversation about faith on the island.

It revealed that Fidel had been profoundly marked by a deeply Catholic childhood, raised by a fervent mother who prayed daily and lit candles to the saints, as well as by equally devout aunts and uncles.

At the age of five he was sent by his distant father to Santiago de Cuba, where he was educated by the De La Salle brothers, and later by Spanish Jesuits at the prestigious 1,000-pupil Colegio de Dolores, where he boarded, and which became for him a substitute family. “They were people who had a great interest in their pupils, their character and behavior,” Castro told Betto. “They were rigorous and demanding.”

He later went on to the Colegio de Belén in Havana, where he formed close relationships with many of the teachers. Fr IU

The Jesuits — “incomparably superior” people, as he described them — taught Castro fibre, discipline, and commitment, traits that would later serve him well on the Sierra Maestra, the mountain range which for years served as his guerrilla base preparing for the revolution that would eventually overthrow the dictator Fulgencio Batista.

The Jesuits “influenced me with their strict organization, their discipline and their values … They influenced my sense of justice,” he told Betto.

Castro’s break with the Church, Betto’s book showed, was essentially political. He regarded the Church of the 1940s-50s as a socially reactionary institution which defended the existing social order, and which in Fidel’s eyes tolerated and justified the vast inequalities and injustices of his day.

Yet the guerrillas he led in the 1950s were not mostly atheists: they even had a chaplain, appointed by his bishop to baptize the babies born in the Sierra Maestra, and to bury the dead revolutionaries. (Pope John XXIII even authorized the chaplain, Guillermo Sardiña, to wear an olive-green cassock.)

But as the revolution turned atheist and communist, and the clergy turned against it, in Fidel’s binary politics, the Church was an enemy of the revolution. Even though, as he would later insist, the revolution was never (unlike, say, in Mexico) anti-religious, and no priest was ever killed by the communist state, his crackdown was nonetheless brutal.

In 1961, Castro had his old school shuttered and the Jesuits expelled from the country. The clergy was reduced to just 200 on the whole island, and attending Mass came to be seen as an act of subversion.

The Betto interview constantly hovers around the question of the nature of Castro’s break with Catholicism, and implicitly asks whether, if Castro had been schooled after the Second Vatican Council and Medellín, he would still have been an anticlerical revolutionary.

The question is never really answered. But Betto showed Fidel as having an essentially 1950s view of the Church, and how fascinated he was by developments since the 1960s, above all by the attempt to blend Marxist social analysis with the Gospel in some strains of liberation theology.

The publication of Fidel y la Religión helped to overcome some of the deep hostility between Catholics and Marxists, and for Cubans themselves to begin a conversation about faith and the revolution.

Following the collapse of the Soviet Union, the 1992 constitution declared that Cuba was no longer officially atheist, and freedom of worship was restored. In the appalling hardships that followed the loss of $5 billion in Soviet subsidies — Cubans call this, with some irony, “the special period” — the Church became a significant presence again, its clergy numbers allowed to double.

Although Castro kept the Church, like all institutions on the island, on a short leash — seminaries and religious houses in Cuba have had their fair share of government informers — he increasingly came to see it as a partner, rather than an enemy. But he never quite shook off his suspicion of Catholicism as a rival, a socially conservative body with political ambitions that needed to be kept in check.

An important breakthrough came in the January 1998 visit by John Paul II, who urged Cuba to open to the world and vice-versa, urging democracy and human rights while strongly critiquing the U.S.-imposed embargo.

Throughout his visit, recalls George Weigel in his papal biography Witness to Hope, Castro “combined a striking deference to the pope with continuous anti-American propaganda,” while looking to some observers “like a man who wanted, somehow, to go to confession, to the one man in the world to whom his ego would allow him to confess.”

The visit was accompanied by significant gestures such as the release of 100 prisoners and the restoration of Christmas as a holiday. But the visit made little initial difference to Church-state relations. It wasn’t until 2002 that the regime finally called the island’s 13 bishops in for talks.

After that, dialogue between Church and state became far more fluid — and has accelerated since 2008 under Raúl Castro. The Church has gradually emerged as the largest civil-society actor and the key non-state social provider in Cuba, staking out a significant autonomy in spite of tight controls.

In all of this, Fidel’s personal faith has remained something of a mystery. Yet rumors abounded of signs of a rapprochement with the faith of his childhood.

On the eve of Pope Benedict’s visit, there were rumors that Fidel was seeking a return to the Church. La Repubblica quoted an unidentified high-level figure in the Vatican to the effect that Fidel was at the end of his strength and that “in this last period he has come closer to religion and God.”

The newspaper also quoted Castro’s daughter Alina, who appeared to confirm as much. “Fidel has come closer to religion: he has rediscovered Jesus at the end of his life. It doesn’t surprise me because dad was raised by Jesuits.”

If Fidel was received by Benedict XVI in 2012, it was never made public, and there was no talk of conversion when Francis met the ailing, 89-year-old, tracksuit-wearing Fidel in 2015 for a 40-minute informal encounter that both — judging by the photos later sent out by Castro’s son Alex — clearly enjoyed.

The gifts the pope gave him were clearly intended to help el comandante come to terms with his past.  While the Cuban leader gave Francis a copy of his Betto interview, Fidel y la Religión, the pope handed Fidel several books, including ones by an Italian priest, Alessandro Pronzato, whose first (1965) book was called The Frontiers of Mercy.

The Pope also gave him a book and a CD of homilies by Father Amando Llorente SJ, the Spanish Jesuit who taught Fidel Castro at the Colegio de Belén in the 1940s, and who remained in contact after Castro left school. Llorente was one of those whom Castro had expelled in 1961, and who, from Miami, once revealed that Castro had described him a substitute father.

That gentler, vulnerable side of Fidel — the lonely child missing his father, who turned on his mother’s piety as he turned to revolutionary politics — has seldom revealed itself in public, but perhaps Francis had spotted it.

The pope’s gifts were good texts, one might say, for a man looking back on a life and political career characterized by charismatic genius but lacking in mercy — especially towards those seen as his opponents.

The progress of Fidel’s soul since then is mostly shrouded in mystery, but for one tantalizing if rambling piece he wrote recently for Granma, Cuba’s official communist daily.

Entitled ‘The Uncertain Destiny of the Human Species’, the October 9th article noted how “there are many more qualities in religious principles than uniquely political ones” and that “many of the most inspired artistic works were born of hands of religious people.” Observing that the great achievements of science did not preclude theories of God’s creating the universe, Fidel’s article acknowledges how important religions are to humanity.

It shows, if nothing else, that religion was on his mind in his final days.

He ends by noting that he knows a fair bit about Jesus Christ because of what his Jesuit and de la Salle schools taught him, and how he recalls the bible stories of Adam and Eve, Noah and the Ark, as well as “the mannah that fell from heaven when as a result of droughts and other causes there was a lack of food.”

It is an intriguing story to pick out from the Bible — an example of where the needs of the people were met neither by the free market, nor by socialist central planning, but the providence of a benign creator.

He adds: “I shall try on another occasion to transmit further ideas about this singular problem.”

He never did, and the faith of his final hours will probably always remain a mystery.