— In a final appearance before beginning his retirement behind Vatican walls, Pope Benedict XVI on Wednesday told an adoring crowd — the sort that has mostly eluded him during his eight-year reign — that “to love the church means also to have the courage to make difficult, painful decisions, always putting the good of the church before oneself.”

More than a hundred thousand people packed St. Peter’s Square on a crisp and sunny day to listen to the departing pontiff, dressed in white cassock, zucchetto and broad-lapelled blazer.

About 70 of the church’s cardinals, who are now tasked with selecting Benedict’s successor, sat to his right on the steps before St. Peter’s Basilica. To his left sat ambassadors representing myriad countries. Flags from nations around the world were held aloft and waved by people in the vast crowd below.

They all listened to Benedict, 85, visibly frail but in good spirits, as he recalled that upon his election as pope on April 19, 2005, he thought, “Lord, what do you ask of me?”

But, he added, he had faith that God would guide him.

“It was a journey for the church that had moments of joy and light,” but also darker moments, “in which the waters were rough and the wind was at its face . . . and the Lord seemed to sleep,” Benedict said. “But I have always known that the Lord is in that ship and that the ship of the church is not mine. It is not ours. It is His, and the Lord will not let it founder.”

Benedict tried but was unable to reverse the erosion of the church in the Western world during his tenure. During his watch, he saw a global explosion of the sexual-abuse crisis that had festered under his predecessor, John Paul II, and a seemingly incessant flow of scandals coming out of the church government that he struggled to manage. The dysfunction did not relent in the months, weeks and days leading up to the pope’s farewell, with a papal-letter-leaking scandal, swirling rumors and fresh abuse accusations against one of the voting-age cardinals.

But in his last public appearance, Benedict pointed to the sea of faithful spilling out of the square and into the broad avenue leading to the basilica, which the Vatican, citing authorities, estimated at 150,000 people. “In a time in which many talk of our decline,” Benedict said, “we see that the church is alive today.”

The pope then ruminated on his own historic decision to step down as leader of the world’s 1 billion Catholics.

“In these last months, I felt my strength diminished, and I asked God with insistence, and in prayer, to illuminate for me with His light the right choice not for my good, but for the good of the church,” Benedict said.

Again recalling his election, he said he knew full well in 2005 that he who assumes the mission of the pope “no longer has any privacy,” and that in his total service to the church “the private dimension” of one’s life is completely stripped out. The pope “no longer belongs to himself, he belongs to everyone.”

Perhaps in a nod to his decision to keep the title of His Holiness and to be known as pope emeritus, he said that for a pope “there is no return to the private” and that “my decision to renounce the active exercise of the ministry does not revoke this. I will not return to a private life, to a life of travel, meetings, receptions conferences, etcetera.”

He said that while he no longer holds office, he will serve the church through prayer. He asked the crowd to keep him in their prayers, as well, but also asked that the gathered masses pray for the cardinals now gathering in Rome to begin the highly ritualized, secret work of picking his successor.

As Benedict spoke of his sacrifice for the church, some of those cardinals wept. The pope thanked the Roman Curia, the bureaucracy that governs the church, which he himself served in for decades as Cardinal Joseph Ratzinger, the Holy See’s chief doctrinal watchdog. He singled out his second-in-command, Secretary of State Tarcisio Bertone, who has been cast as a villain in many of the recent Vatican scandals, as “accompanying me in the faith in these years.”

The pontiff, whose reign was arguably compromised early and often by public relations missteps, also thanked all the people who worked in communications “for their important work.”

Before Benedict’s appearance in the square, street venders hawked papal souvenirs and newspapers reading “Grazie Benedetto.” The variety of the people in the crowd, and their concerns, showed the deep challenges the next pope will inherit.

Vinvenza Lorito, 74, visiting Rome from the Italian region of Abruzza for the first time in 40 years, said she considered the pope a great theologian “who wasn’t right for the times.” She said that while she believed that he was leaving because of his advanced age, “there are other factors as well. Every day you hear a new thing about the church on the television.” She said she hoped the next pope would be a “young person” with the force to “clean up the church.”

Jihad Krayem, a 33-year-old Franciscan from Lebanon dressed in brown robes, said the pope’s resignation was itself his most important achievement. “We have all these leaders who never want to let go of power and they kill each other over it,” Krayem said, standing next to a friend waving a Syrian flag who declined to give his name for fear of retribution against his family back home.

Krayem called Benedict’s resignation a “prophetic gesture” and said he hopes that the next pope would be “a good pastor who protected his flock.”

Standing under Chinese flags, the Rev. Joseph Zhan, from Beijing, said he hoped the new pope would come to China and also hoped that the “Chinese government would give more liberty to the church. Because the people need the good news to lead a better, more moral life.”

Then Benedict arrived, standing in the back of his popemobile, taking a last spin in the square through a grid of pathways that wove through the packed crowd. Children climbed on lampposts. Old women craned their necks.

The popemobile deposited Benedict atop the stairs before the Basilica. He was helped to his throne by his personal secretary, Archbishop Georg Ganswein, who will live with him in a monastery behind the Vatican walls but also serve the new pope — another source of controversy.

“I’m glad you are so many here,” Benedict said, looking out at the crowd, expressing his “heartfelt thanks.”