(CNN) -- Pope Benedict XVI said goodbye to his native Germany on Sunday, capping a packed four-day visit in which he met with political and religious leaders in a country that -- like many others in Europe -- has seen growing disenchantment with the Roman Catholic Church.
The pontiff began his day by celebrating Mass in Freiburg. He discussed God's endless sense of mercy and forgiveness, that it's better to be agnostic and have a "pure heart" over being nominally Catholic and seeing the Church "merely as an institution," and other lessons from the Bible, according to a transcript of his remarks from the Vatican press office.
He also spoke specifically about the Church within Germany, which has been rattled by the still-simmering clergy sex abuse scandal and a perception among some Germans that it is too conservative to change with the times.
"The Church in Germany will overcome the great challenges of the present and future, and it will remain a leaven in society, if the priests, consecrated men and women, and the lay faithful -- in fidelity with their respective vocations -- work together in unity," Benedict said. "The Church in Germany will continue to be a blessing for the entire Catholic world."
The pontiff later had lunch with German bishops, before eventually heading by motorcade to the Black Forest Airport Lahr near Freiburg and the French border. There, he met with German President Christian Wulff and his wife Bettina and then said a final prayer before boarding a plane back to the Vatican.
The visit was Benedict's first state visit to Germany since becoming pope in 2005, though he had made multiple less official trips home in that time.
It included a talk with German Chancellor Angela Merkel, as well as a meeting Friday at a seminary in Erfurt with a group of people who had been sexually abused by clergy and church personnel in Germany. He also met there with people "who care for those injured by these crimes," according to a statement from the Vatican press office.
"Moved and deeply shaken by the sufferings of the victims, the Holy Father expressed his deep compassion and regret over all that was done to them and their families," the statement added. "He assured the people present that those in positions of responsibility in the church are seriously concerned to deal with all crimes of abuse and are committed to effective measures for the protection of children."
The pope has had similar meetings elsewhere, in the face of outcries from many nations in Europe, North America and beyond criticizing the church for its handling of sexual abuse cases.
Benedict himself got caught up in the scandal in at least one case, when he -- as Cardinal Joseph Ratzinger -- approved the transfer of a man within Germany in the wake of accusations that the man had abused children.
But the archdiocese has said the then-cardinal was never personally aware of the details of the man's case. In March 2010, the priest -- then identified only as H -- was suspended, the archdiocese of Munich and Freising announced.
On Saturday, Benedict visited a predominantly Protestant region in former Communist eastern Germany and also made a stop in the traditionally Catholic southwest, which has enjoyed democratic freedoms since shortly after World War II.
Catholic and Lutheran denominations alike have lost membership, but for decades German attrition hit the Protestant Church harder. Still, the enthusiasm that greeted Benedict's appointment as pope has dissipated significantly since then.
According to Der Spiegel magazine, more than 181,000 Catholics have left the church since the scandal broke. And candidates for the priesthood have plummeted 62% since 1990, according to the German Bishops Conference.
CNN's Ben Brumfield and Rick Noack contributed to this report.