The pope's visit to Fatima, marking the 93th anniversary of an alleged appearance of the Virgin Mary to three shepherd children, was the highlight of his four-day trip to Portugal.
The pope began his stay in Fatima by visiting the Chapel of the Apparitions, where he thanked the Virgin's "invisible hand" for saving John Paul II from an assassination attempt at Saint Peter's Square in 1981.
It was "profoundly consoling" to see the statue of the Virgin wear a crown which contained the bullet fired by Turkish Mehmet Ali Agca on that day, the pope said.
He left at the sanctuary a golden rose, a symbolic tribute by popes to special places.
The pope then continued in the popemobile for vespers at the Church of Holy Trinity, where he was cheered by thousands of faithful.
On Thursday, the pope was scheduled to celebrate an open-air mass in Fatima, where he came from Lisbon. His last stop will be Porto, Portugal's second-largest city, on Friday.
The six supposed apparitions of the Virgin Mary to Francisco and Jacinta Marto and to Lucia dos Santos - then aged between seven and 10 - began on May 13, 1917.
The memory of those events now brings millions of pilgrims annually to Fatima, a town of about 10,000 residents.
The Virgin is believed to have revealed a number of secrets, including the end of World War I, the outbreak of World War II and the "reconversion" of communist Russia to the Christian faith.
The third secret was partly revealed by John Paul II during his third visit to Fatima in 2000. It prophesied the murder attempt against him by Ali Agca.
On the plane from Rome to Portugal on Tuesday, Benedict XVI told journalists that the third secret could also be interpreted as being related to the "suffering" the church is undergoing today over sexual abuse of children by some of its priests.
The pope condemned such abuse in exceptionally strong terms, saying that "forgiveness" could not replace "justice."
His trip came after the Vatican has been convulsed by months of paedophile and abuse scandals in many of its most staunchly Catholic heartlands - from Ireland to Germany.
Earlier on Wednesday, the pope met Portuguese Prime Minister Jose Socrates - a driving force behind the liberalization of Portugal's abortion laws and plans to legalize same-sex marriage - who told him that the state had "excellent" relations with all the religions present in the country.
On meeting about 1,500 Portuguese personalities, the pontiff commented on the church's "dialogue" with other faiths, saying it was learning to "live with respect for other 'truths'" while continuing to proclaim the Christian faith.
In all his speeches or homilies delivered in Portugal so far, Benedict has also stressed the importance of the country's Christian identity in the past and present.
Nearly 90 per cent of the Portuguese identify themselves as Catholics, but church attendance continues to decline.