Morocco was in shock Sunday after emergency crews found a five-year-old boy dead at the bottom of a well in a tragic end to a five-day rescue operation that gripped the nation and the world.

The ordeal of "little Rayan" since he fell down the 32-metre (100-foot) dry well on Tuesday gained global attention and sparked an outpouring of sympathy online, with the Arabic Twitter hashtag #SaveRayan trending.

Graphic on the failed rescue operations to save a a five-year-old child who fell into a well in Morocco
Graphic on the failed rescue operations to save a a five-year-old child who fell into a well in Morocco AFP / Emmanuelle MICHEL

Pope Francis, while mourning the loss of Rayan, praised the "beautiful" sight of "how all the people gathered together" to try to save a child.

"Our hearts broke last night," Israeli President Isaac Herzog said in a condolence message to King Mohammed VI, while French President Emmanuel Macron said to Rayan's family and the Moroccan people: "We share your pain."

There was no official information about an autopsy but a cousin told AFP that Rayan's body had been transported to a military hospital in the capital Rabat.

A Moroccan security officer gestures to the crowd to move back as the ambulance carrying Rayan Oram's body departs
A Moroccan security officer gestures to the crowd to move back as the ambulance carrying Rayan Oram's body departs AFP / Fadel SENNA

His funeral is to be held on Monday in the family's village of Ighrane where the accident took place, provincial representative Abderahim Bouazza and a relative said.

"The silence is terrible this morning in the village," a relative said.

Map locating the village Ighrane where emergency crews found a five-year-old boy dead at the bottom of a well in a painstaking five-day rescue operation
Map locating the village Ighrane where emergency crews found a five-year-old boy dead at the bottom of a well in a painstaking five-day rescue operation AFP / Emmanuelle MICHEL

Earlier, the boy's father Khaled Aourram said he was repairing the well when his son fell in, close to the family home in the Rif mountains of northern Morocco.

"We thank His Majesty the King, the authorities and all those who have helped us," Aourram said on television Saturday evening. "Praise God, have mercy on the dead."

The parents of five-year-old Rayan arrive at the scene of the rescue effort, late on February 5, 2022
The parents of five-year-old Rayan arrive at the scene of the rescue effort, late on February 5, 2022 AFP / Fadel SENNA

Throughout the major digging operation to extricate Rayan, authorities had cautioned that they did not know whether he was alive.

Thousands of bystanders converged on the site where rescue crews excavated the surrounding earth before creating a horizontal tunnel
Thousands of bystanders converged on the site where rescue crews excavated the surrounding earth before creating a horizontal tunnel AFP / Fadel SENNA

The shaft, just 45 centimetres (18 inches) across, was too narrow for the boy to be reached directly, and widening it was deemed too risky -- so earth movers dug a wide slope into the hill and then a horizontal connecting tunnel to reach him from the side.

But progress slowed as the drill teams worked by hand to avoid any vibrations that might bring the brittle soil down on the child, local authorities said.

Late Saturday evening, crowds cheered when the rescue workers broke through the final stretch of earth to reach the boy, and volunteer digger Ali Sahraoui cleared the last soil away with his hands.

A Moroccan security officer gestures to the crowd to move back as the ambulance carrying Rayan Oram's body departs
A Moroccan security officer gestures to the crowd to move back as the ambulance carrying Rayan Oram's body departs AFP / Fadel SENNA

"We hoped to bring him out alive," the man in his 50s told AFP.

But soon after, AFP correspondents saw the boy's parents walk down the slope into the horizontal tunnel, visibly crushed. They returned and boarded an ambulance without saying a word.

It was Morocco's royal cabinet that announced he had been found dead.

"Following the tragic accident which cost the life of the child Rayan Aourram, His Majesty King Mohammed VI called the parents of the boy who died after falling down the well," a statement from the royal court said.

Thousands of people had gathered beside the giant pit to watch the effort, singing songs to urge on the diggers, who worked through the nights under floodlights.

Many of the watchers prayed, chanting in unison "Allahu akbar" (God is greatest).

"I couldn't sleep for the five days," Mounir Adbib, a neighbour, told AFP. "I have a son the same age as Rayan. I think about him every time I see my little one."

Work began Sunday to fill areas that had been excavated for the rescue operation, AFP correspondents said.

The race to rescue Rayan was followed live across the world, and as soon as the tragic conclusion was announced, tributes poured in.

Residents encountered on the streets of Rabat were in shock.

"It touched us because we also have children and we hoped he would survive because we loved this child, but God willed it," said Amina Benkhaleq, a salesperson.

Another resident, Mourad Fazoui, called it a disaster. "May his soul rest in peace and may God open the gates of heaven to him," the salesman said.

But some saw the event differently, with one internet user deploring a "dystopic world where all the Arab nations are moved by the rescue of a child in Morocco" while others die due to famine or conflict in Yemen and Syria. The writer added: "All lives matter."