A two-year-old boy trapped in a well in Spain for nearly two weeks has been found dead by rescuers who had been attempting to reach him.

Hundreds of people had been working round-the-clock under the media glare to try to reach Julen Rosello, who fell down the narrow borehole on January 31 while on an outing with his parents in Totalan, a southern town near Malaga.

Rosello's body was found at the depth of 70 metres early on Saturday, according to the regional government.

"Unfortunately at 1:25 am the rescue team reached the spot where they were looking for Julen and found the lifeless body of the little one," the central government's representative in the southwestern region of Andalusia, Alfonso Rodriguez Gomez de Celis, wrote on Twitter.

A hearse arrived at the site shortly after the news broke to take the body to a funeral home.

There had been no sign of life from the boy, but rescuers believed they knew where he was inside the illegal well.

The only evidence of the boy's presence were some strands of hair that matched his DNA and a bag of candy that he had been holding when he fell into the well.

"All of Spain feels the infinite sadness of Julen's family. We have followed closely every step to reach him," Prime Minister Pedro Sanchez wrote on Twitter.

"We will always appreciate the tireless effort of those who searched for him during all these days."

In a tweet, Spain's King Felipe VI extended his "deepest condolences to Julen's whole family".

Complex operation

According to media reports, the well with a 25-30cm diameter was dug illegally.

The complex search-and-rescue operation had been fraught with complications that caused delay upon delay as the boy's distraught parents and relatives stood by.

Rescuers were not able to get to Rosello via the well he fell down because it was blocked by a layer of earth, sand and stones believed to have been dislodged when he tumbled into the shaft.

They decided to dig a vertical shaft parallel to the well, 60 metres deep, which was finished late on Monday.

The idea was to secure the shaft with tubes then take elite miners down in a specially made cage to start digging a horizontal tunnel to the site where they believe the child was.

But the tubes designed to secure the shaft did not fit, so they had to widen it, which delayed the operation further.

Eventually, they succeeded and expert miners on Thursday began painstakingly digging a four-metre tunnel to join both channels to reach Rosello with the help of four small, controlled explosions.

The miners worked in teams of two and were equipped with oxygen tanks.

Each small explosion took about two hours, which slowed down the rescue attempt.

Two miners had to first go down the shaft and bore a few holes. They were then followed by two specialised officers who set up the explosives.

Once they returned above ground, the explosives were detonated and then the rescue team had to wait half an hour to clear the shaft of polluted air.