A small boy trapped in a well in northern Morocco for five days died before rescuers were able to reach him late on Saturday and retrieve his body, two government officials said.
Footage posted on social media showed the scene after his body was recovered, with hundreds of distraught rescue workers and onlookers gathered at the site shining the flashlights of their phones into the air.
Rayan Awram, aged five, fell into the well at his village of Ighran in the hills near Chefchaouen on Tuesday, triggering a huge rescue effort that engrossed the country.
Rescuers finally reached him late on Saturday after removing much of the adjacent hillside and delicately tunnelling a horizontal passage into the well.
King Mohammed sent condolences to his parents, a statement carried by state media reported.
The well was only 45 cm wide at the top and tapered as it dropped 32 metres to the bottom, where Rayan was trapped, making it impossible for rescuers to descend directly.
A male relative of the boy said on Friday that the family had first realised he was missing when they heard muffled crying and lowered a phone with its light and camera switched on to locate him.
"He was crying 'lift me up'," the relative said.
The hilly region around Chefchaouen is bitterly cold in winter and rescuers attempted to keep the boy alive by lowering food, water and oxygen through a tube.
Rescuers worked round the clock cutting a massive trench through the hillside, with a constant risk of triggering landslides.
In the final hours of the rescue effort, workers had to move with extreme caution as they attempted to dig through earth and rocks to where Rayan lay.
They were eventually able to access the well late on Saturday, and carried his body to a waiting ambulance.
Crowds had gathered in a vigil at the scene to watch the rescue effort as hundreds of workers toiled to save the child. Across the country, Moroccans followed the saga on television in homes and cafes.


Trump appoints envoy to Greenland, stirs backlash
Passenger bus crash in Indonesia kills at least 16 people
Japan prepares to restart world's biggest nuclear plant
Remaining 130 abducted Nigerian students have been released, official says
Failed homemade bombs thrown before Bondi shooting, police tell court
Malaysia court denies ex-PM Najib's bid to serve jail sentence at home
Australian PM booed as Bondi Beach attack victims honoured
Kremlin: Revised US proposals don't improve peace outlook
