Liberation theologians often critical of Vatican policies have responded in kind, led by Leonardo Boff, a former Franciscan priest who in 1985 was ordered not to write or speak publicly for a year because of his positions by the Congregation for the Doctrine of the Faith, headed at the time by Cardinal Joseph Ratzinger, the future Benedict. Now an emeritus professor of the philosophy of religion at the state university here in Rio, Mr. Boff just last week published a laudatory biography of the pope.

“It doesn’t matter that Pope Francis doesn’t use the expression ‘theology of liberation,’ ” Mr. Boff said recently. “What is important is that he speak and act on behalf of the liberation of the poor, the oppressed and those who have suffered injustice. And that is what he has done, with indubitable clarity.”

One of the principal complaints of the protests that have swept Brazil is excessive official spending in the face of pressing social needs, mainly the billions being spent on sporting events — but the $52 million the government is contributing to the youth conference and papal visit has also been sucked into the fray. Cardinal Scherer defended the expenditure, which accounts for about a third of the visit’s total cost, as good for Brazil.

“This money is being spent in Brazil, and as such it is welcome,” he said at a news conference in São Paulo. “These are not expenses paid to someone who is going to leave with the money. It’s generating taxes, jobs and so on. It is, without a doubt, an injection of blood in the economy.”

At Francis’ request, the original itinerary prepared for Benedict has been expanded to include a visit to Aparecida, site of Brazil’s biggest shrine to the Virgin Mary. It was also there, during a visit by Benedict in 2007, that Francis, then Cardinal Jorge Mario Bergoglio, scored a personal triumph by presiding over the writing of an important policy document that was presented to the pope on behalf of the Latin American Episcopal Conference.

The document emphasized social justice and evangelization, an issue that remains critical to the Brazilian church, even more than in the rest of Latin America. When John Paul made the first visit by a pope to Brazil, in 1980, nearly 90 percent of the population considered itself Catholic; by the 2010 census, that had fallen to under two-thirds, with the number of Brazilians calling themselves Protestants rising to 22 percent from 6 percent during the same period.

The situation here in Rio underscores the growing challenge to the Catholic church. According to census data, the growth of evangelical Protestantism, secularism and African-Brazilian faiths like candomblé has been so pronounced that Catholics no longer constitute a majority of the population in Rio de Janeiro State.

“No one in the Catholic leadership is going to say there is competition with the evangelicals, but that’s clearly a motivation for this event,” said Clemir Fernandes, a researcher at the Institute for the Study of Religion here. “The evangelicals have a lot of TV and radio exposure in Brazil, but a pope’s visit gets a lot of positive media coverage. That’s good for the church and, by strengthening belief among those already belonging to the faith, can perhaps help stem the erosion.”