Rescue workers in northern Morocco had been digging around the clock to rescue the boy.
Footage from the scene in the north of the country showed workers emerging from a tunnel – dug specifically for the rescue – carrying the child, Rayan Awram, on Saturday evening.
An Associated Press reporter at the scene saw him wrapped in a yellow blanket at his village of Ighara.
His parents were taken to an ambulance before he emerged.
In a statement, King Mohammed VI expressed his condolences to the boy’s parents.
Two government officials said Rayan died before rescuers reached him.
RIP young man