Pope Francis's visit to Brazil takes him to one of the most important countries for the future of Catholicism in the world. It is not just that Brazil has the world's largest number of Catholics (123m) in a single country. It is also a place where the church is increasingly challenged, partly by the growth of Pentecostal Christianity and even now by a general disaffection from organised religion.

The slack has overwhelmingly been taken up by Pentecostalist denominations, which flourish especially in the urban areas. Unusually for religious decline, this has been a gender-neutral process, with both men and women leaving the Catholic church at equal rates. For many years the proportional decline was masked by the enormous population growth of Brazil as a whole, so that the absolute number of Catholics increased even as their relative number diminished. In those years the Catholic church used to refer to the evangelicals dismissively as sects. But since 2000 the absolute number of Catholics has been level or falling, and this comfort is no longer available.

The reasons for evangelical growth are complex. Much has to do with the excitement of their services, the extraordinary flexible and decentralised character of the movement, which can respond very quickly to pressures in the religious market. Although it is formally patriarchal, charismatic Pentecostalism can offer women much greater scope than traditional Catholicism. Women can prophesy as well as men can, and because leadership structures are very much more fluid it is much easier to harmonise with a working life in the secular world.

Francis has been associated with a determined attempt by the church to resist this problem, which is general across Latin America. At a meeting in Brazil in 2007, the Catholic bishops did admit that this was largely their own fault.

"If Catholics are leaving the church and finding a spiritual home in Pentecostal communities, it is not the fault of those individual Catholics but of the church. The Catholic church must honestly ask herself what is missing in her presentation of the gospel and the authentic, full living of the gospel. Unless we are blatantly honest without our past errors, current malaise, lack of creativity and inability to connect with the modern world, and without a willingness to fill those gaps, we will continue to witness massive departures of the faithful from the Catholic church."

But the problem goes deeper than that. The Catholic church was weakened by decades of infighting over liberation theology in the 70s and 80s, when its own internal divisions mirrored those of the violent and sometimes revolutionary societies around it. As a Jesuit in Argentina, the future Pope was deeply enmeshed in these controversies, accused by the left of being an authoritarian stooge of the junta, but at the same time developing a mordant critique of capitalism and a preference for the poor that he has carried into office.

Like most global Christian leaders, the pope sees the future of Christianity as being in the poor and populous south rather than its traditional European and Mediterranean cradle. In the south, Christianity is still profoundly entangled with everyday life in a way that just isn't true in Europe or in increasing parts of North America. But distance from Christianity is growing even in Latin America. "Nones" – those who profess no religion at all – formed 8% of the Brazilian population in 2010, up from negligible levels in the past. In the long run, it is not theological or political hostility that threatens the Latin American church nearly as much as indifference.