Rescuers have found the body of a two-year-old boy who fell into a deep well nearly two weeks ago in southern Spain, triggering an unprecedented rescue operation fraught with glitches that had kept the country on tenterhooks.

Hundreds of people had been working round-the-clock to try to reach Julen Rosello, who plunged down a narrow shaft which is more than 100 metres deep on 13 January.

"Unfortunately at 1:25am 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 his 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 sweets 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."

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

Rescuers were not able to get to Julen 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 still further.

Julen's parents lost another child, Oliver, aged three, in 2017

Eventually, they succeeded and expert miners on Thursday began painstakingly digging a four-metre tunnel to join both channels to reach Julen 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.

Despite the passage of time, the boy's relatives held out hope that he had somehow survived the fall and would be found alive.

Jose Rosello, Julen's father, told reporters that "we have an angel that will help my son come out alive as soon as possible".

Julen's parents lost another child, Oliver, aged three, in 2017. The child had cardiac problems.

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

The well was unmarked at the time of the accident, and regional authorities in Andalusia said the necessary permission had not been sought before it was dug.