Pope Francis, dubbed the "slum pope" for his work with the poor, received a rapturous welcome Thursday from one of Rio's most violent shantytowns and demanded the world's wealthy end the injustices that have left the poor on the margins of society.

The visit to the Varginha shantytown came hours before the pope was to preside over the opening of World Youth Day in a far different setting: Rio's upscale Copacabana Beach.

Amid the stench of raw sewage and the shrieks of residents, Francis made his way through Varginha, part of a region so violent it's known as the Gaza Strip. He seemed entirely at home, wading into the cheering crowds, kissing residents young and old and telling them the Catholic Church was on their side.

It was a message aimed at reversing the trend in much of Latin America that has seen legions of Catholics, most of them poor, leaving the church for Pentecostal and evangelical congregations. These churches have taken up a huge presence in favelas, or shantytowns like Varginha, attracting souls with nuts and bolts advice on how to improve their lives.

"No one can remain insensitive to the inequalities that persist in the world!" Francis told a crowd of thousands who braved a cold rain and stood in a muddy soccer field to welcome him. "No amount of peace-building will be able to last, nor will harmony and happiness be attained in a society that ignores, pushes to the margins or excludes a part of itself."

Francis' open-air car was mobbed on a few occasions as he headed into Varginha's heavily policed streets lined with brick shacks, but he never seemed in danger. He was showered with gifts as he walked down one of the slum's main drags without an umbrella to shield him from the rain. A well-wisher gave him a paper lei to hang around his neck and he held up a scarf from his favorite soccer team, Buenos Aires' San Lorenzo, that was offered to him.

"Events like this, with the pope and all the local media, get everyone so excited," said Antonieta de Souza Costa, a 56-year-old vendor and resident of Varginha. "I think this visit is going to bring people back to the Catholic Church."

It was one of the highlights of Francis' weeklong trip to Brazil, his first as pope and one seemingly tailor-made for the first pontiff from the Americas. Later Thursday, he was to preside over a welcoming ceremony on Copacabana beach for World Youth Day, his first official event with the hundreds of thousands of young people who have flocked to a rain-soaked Rio for the Catholic youth festival.

In an indication of the havoc wreaked by four days of steady showers, organizers made an almost unheard-of change in the festival's agenda, moving the Saturday vigil and climactic Sunday Mass to Copacabana Beach from a rural area 30 miles (50 kilometers) from the city center. The area, Guaratiba, has been turned into a massive field of mud, making the overnight camping plans of the pilgrims untenable.

Francis added a last-minute tweak of his own to his busy schedule, meeting with pilgrims from his native Argentina at Rio's cathedral Thursday afternoon.

He told the thousands of youngsters — an estimated 30,000 Argentines are registered — to get out into the streets and spread their faith, saying that a church that doesn't go out and preach simply becomes an NGO, or non-governmental organization.

"And the church cannot be an NGO!" he said to wild applause.

Francis' visit to the Varginha slum followed in the footsteps of Pope John Paul II who visited two such favelas during a 1980 trip to Brazil and Mother Teresa who visited Varginha itself in 1972. Her Missionaries of Charity order has kept a presence in the shantytown ever since.

Like Mother Teresa, Francis brought his own personal history to the visit: As archbishop of Buenos Aires, then-Cardinal Jorge Mario Bergoglio frequently preached in the poverty-wracked slums of his native city, putting into action his belief that the Catholic Church must go to the farthest peripheries to preach and not sit back and wait for the most marginalized to come to Sunday Mass.

In remarks to Varginha's residents, Francis acknowledged that young people in particular have a sensitivity toward injustice.

"You are often disappointed by facts that speak of corruption on the part of people who put their own interests before the common good," Francis told the crowd. "To you and all, I repeat: Never yield to discouragement, do not lose trust, do not allow your hope to be extinguished. Situations can change, people can change."

It was a clear reference to the violent protests that paralyzed parts of the country in recent weeks as Brazilians furious over rampant corruption and inefficiency within the country's political class took to the streets.

Francis blasted what he said was a "culture of selfishness and individualism" that permeates society today, demanding that those with money and power share their wealth and resources to fight hunger and poverty.

"It is certainly necessary to give bread to the hungry — this is an act of justice. But there is also a deeper hunger, the hunger for a happiness that only God can satisfy," he said.

The Varginha slum butts up against what until about six months ago was the largest "cracolandia" — crackland — in Brazil, where hundreds of crack cocaine users gathered under a train overpass and used the drug openly night and day. Crumbling brittle shacks still give the area a bombed-out feeling.

However, the slum on Thursday was buzzing with excitement. Residents were clearly delighted about all the attention their neighborhood was suddenly getting and they basked in the glow of the flashbulbs, happily granting interviews and striking poses for the hoards of reporters.

Some spectators carried devotional items like rosaries or plaster Virgin Mary figurines, protected from the rain by plastic shopping bags. Lining the police barricades, they chanted "Francis, I love you."

Neighbors said local authorities had been busy in recent days with a flurry of last-minute spruce-ups that included repairing cracked and uneven sidewalks and trimming long-dead limbs from the exuberant tropical vegetation. Security was tight: In addition to the police helicopters, sharpshooters perched atop buildings, metal barricades held the ecstatic crowd at bay on the street and police officers were posted every 5 feet (2 meters).

Francis prayed before a replica of Brazil's patron saint, the Virgin of Aparecida, and met with a family in their squat yellow home.

"He gave each of us a rosary, he took photos with everyone and embraced each one," said Diego Rodrigues, a 26-year-old friend of the da Penha family who received the papal visit. "I think everyone but the pope was speechless!"

Varginha is one of the smallest of Rio's more than 1,000 slums, a triangle-shaped chunk of flat, dusty land sitting between two putrid waterways full of raw sewage. On the third side runs a busy main road with an elevated commuter train that noisily rolls by overhead.

The slum's surroundings somewhat ease security concerns, with the waterways acting as natural boundaries and only two roads 300 yards (meters) apart from one another allowing access.

Police invaded the slum in January and pushed out a heavily armed drug gang known as the Red Command, then set up a permanent police post in the area, which had seen virtually no government presence for decades.

The citywide program started in 2008 to secure Rio de Janeiro before it hosts the 2014 World Cup soccer tournament and the 2016 Olympics.

There are now 33 permanent police posts set up in Rio in communities with 1.5 million people.

Follow us on twitter.com/foxnewslatino
Like us at facebook.com/foxnewslatino