A rescue operation attempting to save him captivated people in Morocco and beyond.
A Moroccan boy trapped in a well for four days did not survive, Moroccan state-run media reported after rescuers pulled out his body on Saturday.
The reports carried a statement from the royal court which said the king of Morocco called the boy’s parents to express his condolences.
The boy, named Rayan, had plunged more than 100 feet down the well near his home in the tiny village of Ighrane, about 60 miles from the city of Chefchaouen, on Tuesday afternoon.
For days, as cameras lowered into the well offered glimpses of hope — though bloodied, Rayan appeared to be moving — tens of thousands of people around the world kept vigil for the child, posting encouragement to Twitter under the hashtag #SaveRayan.
Rescuers had worked day and night trying to extract the boy, first digging in the well itself and then — when they feared that its walls might crumble on him — bulldozing a giant trench beside the well down to within a few yards of where he was stuck.
The well, according to the authorities, narrows as it gets deeper, and the child was trapped in a tight, cramped space that they estimated to be less than 20 inches in diameter.
Video from the scene on Friday evening showed rescuers manually drilling sideways toward Rayan, their work lit by headlamps, as prayers and shouts of encouragement burst from the gathered onlookers.
Rain and hard rock that got in the way of the drilling complicated the process overnight into Saturday, and work proceeded slowly.
One of the rescuers, Abdelhadi Temrani, told reporters on Saturday morning that he still had “great hope” that Rayan was alive, but workers said later in the day that it was difficult to assess the boy’s condition from the cameras. Mr. Temrani said the camera showed the boy lying on his side.
Some onlookers had sat around or spent the night sleeping under nearby trees, waiting to witness the resolution of the crisis. Rayan’s family made couscous, the traditional Moroccan dish, and served it to the crowd. Others distributed bread and dates.
Rayan’s father said he had been in the process of fixing the well, which he owns, when Rayan fell in, but had not realized at first where the boy had gone.
His mother said the family had searched the area when they noticed him gone, not at first suspecting he had tumbled into the well.
Marc Santora contributed reporting from London.