It was well after dark when rescuers finally broke through to the well shaft where the boy was trapped.
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 painstaking five-day rescue operation that gripped the nation and the world.
The ordeal of "little Rayan" since he fell down the well on Tuesday afternoon gained global attention and sparked an outpouring of sympathy online, with the Arabic hashtag #SaveRayan trending.
Throughout the operation to extricate him from the bottom of the 32-metre (100-foot) well shaft, authorities had cautioned that they did not know whether he was alive.
And reflecting the emotions provoked by the drama, 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 Oram, 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.
By mid-afternoon Saturday, rescue crews, using bulldozers and front-end loaders, had excavated the surrounding red earth down to the level where the boy was trapped, and drill teams began creating a horizontal tunnel to reach him from the side.
But progress slowed to a snail's pace as the drill teams worked by hand to avoid any vibrations that might bring the brittle soil down on the stricken child, local authorities said.
AFP correspondents saw the boy's parents walk down the slope into the horizontal tunnel, visibly crushed, before returning and boarding an ambulance without saying a word.
After a period of confusion, a crowd of onlookers began dispersing in sombre silence.
The family was yet to announce the date of the funeral, but according to Muslim tradition it must take place soon, in principle as early as Sunday.
Tributes poured in in the wake of the news that the rescue efforts had failed to recover Rayan alive.
"I want to say to the family of little Rayan and to the Moroccan people that we share your pain," French President Emmanuel Macron said on Facebook.
"Rayan's courage will stay in our memories and continue to inspire us," wrote AC Milan's Algerian midfielder Ismael Bennacer in a tweet accompanied by a drawing of a child being lifted into the sky, carried by a heart-shaped balloon marked with the colours of Morocco.
"We all of us had been holding out hope that little Rayan would make it," Moroccan-American novelist Laila Lalami wrote on Twitter. "This is all so tragic."
Race against time
Thousands of people had gathered and even camped in solidarity around the site in recent days, where AFP reporters have said the tension has been palpable.
Some had applauded to encourage the rescuers, sang religious songs or prayed, chanting in unison "Allahu akbar" (God is greatest).
Workers had tried to get oxygen and water down to the child but it was not clear whether he was able to use them, AFP correspondents reported.
"I keep up hope that my child will get out of the well alive," Rayan's father had told public television 2M on Friday evening. "I thank everyone involved and those supporting us in Morocco and elsewhere."
He said earlier in the week that he had been repairing the well when the boy fell in.
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 to reach him from the side.
The operation made the landscape resemble a construction site, and red-helmeted civil defence personnel had at times been suspended by rope, as if on a cliff face.
Overnight they worked non-stop under powerful floodlights that gave a gloomy air to the scene.
(Except for the headline, this story has not been edited by NDTV staff and is published from a syndicated feed.)