A five-year-old boy who was trapped in a deep well for four days has died, the Moroccan royal palace has said.

King Mohammed VI expressed his condolences to the boy’s parents in a statement released by the palace.

The boy, Rayan, was pulled out on Saturday by rescuers after a lengthy operation that caught global attention.

An Associated Press reporter at the scene saw the boy wrapped in a yellow blanket after he emerged from a tunnel dug specifically for the rescue.

His parents had been escorted to an ambulance before the boy emerged.

Rayan fell into a 105ft well outside his home in the village of Ighran in Morocco’s mountainous northern Chefchaouen province on Tuesday.

He was trapped in a hole too narrow for rescuers to reach safely.

Morocco rescue attempt
Women watch the rescue attempt (Mosa’ab Elshamy/AP)

For three days, search crews used bulldozers to dig a parallel ditch. Then on Friday, they started excavating a horizontal tunnel to reach the trapped boy.

Morocco’s MAP news agency said that experts in topographical engineering were called upon for help.

His distraught parents were joined by hundreds of villagers and others who gathered to watch the rescue operation.

The village of about 500 people is dotted with deep wells, many used for irrigating the cannabis crop that is the main source of income for many in the poor, remote and arid region of Morocco’s Rif Mountains.

Most of the wells have protective covers.

Moroccans used social media to offer their hopes for the boy’s survival, using the hashtag #SaveRayan which brought global attention to the rescue efforts.