A young girl in 19th century peasant costume handed the pontiff a glass of the water from the spring that burst through the ground 150 years ago when a local girl, Bernadette Soubirous, had repeated visions of the Virgin Mary.
The grotto sheltered Benedict from a steady rain but didn't keep out the evening chill as the pontiff, in a red mantle over white robes, prayed and lit a candle.
Benedict later told faithful who carried torches in a procession through the town that by following in Bernadette's footsteps pilgrims enter into the "extraordinary closeness between heaven and earth."
As torch lights twinkled in the night, the pope likened this link between the heavenly and the terrestrial to a "luminous path" which "opens up in human history, even in its darkest moments."
He cited violence, war, terrorism and famine among the world's afflictions and paid tribute to Christians who die for their faith.
Speaking of the pilgrims who flock to Lourdes from around the world, Benedict wondered aloud how many come here "with the hope - secretly perhaps - of receiving some miracle" and upon their return home undergo a spiritual experience which fills them with "hope, compassion, tenderness."
More than 5 million people visit Lourdes every year - some brought to the spring in wheelchairs and stretchers - in hopes that drinking and bathing in the water will heal their ailments. The church has officially recognized 67 miracle cures linked to Lourdes over the years.
Benedict flew to Lourdes, a town in southwest France near the Pyrenees, after saying an outdoor Mass in Paris attended by more than a quarter million Roman Catholics - a show of faith in a traditionally Roman Catholic country that has witnessed a sharp decline in churchgoing in recent years.
In his homily in Paris, Benedict focused on the ills of modern materialism, condemning the unbridled passion for power, possessions and money.
"Has not our modern world created its own idols?" Benedict said, wondering aloud whether people have "imitated, perhaps inadvertently, the pagans of antiquity?"
The main purpose of Benedict's first visit to France as pontiff was the pilgrimage in Lourdes as the shrine marked the 150th anniversary of the apparitions of the Virgin Mary to 14-year-old Bernadette, who later was made a saint.
Riding through Lourdes in his popemobile, the pontiff smiled and waved to cheering crowds of pilgrims wearing windbreakers. In drizzle and chilly wind, the 81-year-old pope walked the final stretch to the grotto.
In the grotto, Benedict stood on the spot where his predecessor, John Paul II, had prayed four years earlier. When John Paul visited in 2004, he was 84 and suffering the final ravages of Parkinson's disease, and he needed help from aides. It was his final trip abroad, and he died the following year.
The pope's Mass in Paris earlier in the day also evoked themes dear to John Paul II, who worried that the affluent West was turning consumerism into a kind of religion and ignoring its Christian roots.
"This is a question that all people, if they are honest with themselves, cannot help but ask," Benedict said in his homily in the French capital, renowned for its luxury goods, fashion sense and cultural riches.
"Have not money, the thirst for possessions, for power and even knowledge, diverted man from his true destiny?" the pope asked.
Benedict blasted modern society's thirst for these new "pagan" idols as a "scandal, a real plague."
France's rail authority, meanwhile, said a train carrying 350 pilgrims to see the pope at Lourdes hit a truck at a railroad crossing near Toulouse, lightly injuring the truck driver. No other injuries were reported.