ROME — Pope Francis on Sunday described as “beautiful” how people rallied around efforts — eventually proven vain — to save the life of a 5-year-old boy who was trapped in a well for days in a village in Morocco.

Francis expressed thanks to the Moroccan people as he greeted the public in St. Peter’s Square. He praised people for “putting their all” into trying to save the child.

Morocco’s royal palace said on Saturday night, shortly after the boy, Rayan, was pulled out of the 105-foot deep well that he had died.

Francis said that amid the world’s bad news, it was ”beautiful” how Morocco’s people rallied for Rayan in a rescue operation that captured the world’s attention.

“We’re used to seeing, reading in the media, so many ugly things, ugly news, accidents, killings,″ the pontiff said. But it was “beautiful,” how, in Morocco, an entire people clung to one another to save Rayan, Francis said.

The pontiff’s praised followed that on Saturday night by King Mohammed VI, who hailed the rescuers for their relentless work and the community for lending support to Rayan’s family.

Hundreds of villagers and others had gathered to watch the rescue operation in the village of Ighran in Morocco’s mountainous northern Chefchaouen province. The child had been trapped in the narrow well since the evening of Feb. 1.

Rayan’s plight eerily struck a sad chord in Italy. In 1981, a 6-year-old boy fell into a narrow well in the countryside outside Rome, eventually plunging nearly 200 feet. Volunteers heard him cry as they dug down in parallel in what ended as a futile three-day bid to save him. Hundreds of people gathered around the rescue site, and millions watched the efforts on state TV.