Three migrants were killed when a fire ripped through a warehouse near Barcelona, injuring around 20 including several who jumped from the three-storey building to flee the flames, Spanish officials said Thursday.

The blaze began on Wednesday evening in an industrial area of Badalona, a Barcelona suburb, where up to 200 migrants were living in squalid conditions, the town hall said.

Firefighters found two bodies outside the building and one on the top floor, fire chief David Borrell told reporters, saying they "couldn't rule out finding more".

Around 20 were hurt in the blaze, including some who jumped out of the building to escape the flames, firemen and medics said. Three were in critical condition while another four sustained serious injuries.

Although the blaze was brought under control earlier in the day, some areas of the warehouse were too dangerous to enter because of extensive structural damage, Borrell said, indicating specialist teams would be brought in.

By mid morning, plumes of smoke could still be seen escaping from the blackened windows and the stench of burning debris could be smelled blocks away.

Firefighters put out the fire in the Spanish warehouse where up to 200 migrants lived
Firefighters put out the fire in the Spanish warehouse where up to 200 migrants lived AFP / LLUIS GENE

Most of those living in the warehouse were illegal immigrants, mainly from sub-Saharan Africa, who managed to earn a little money by selling trinkets on the streets or collecting scrap metal, several fellow residents and neighbours said.

It had no running water and suffered frequent power cuts, they added.

One survivor who was anxiously waiting outside for news of his friends told AFP the power went out just before 9:00 pm and while some tried to fix the problem, a candle fell over, setting light to a mattress.

"There was a lot of us in there, some were already asleep on the terrace or the roof," said Seydou Camara, a man in his 30s who came from Senegal three years ago.

"I was on the terrace on the top floor. I came inside when I heard screaming. I almost couldn't breathe and could see hardly anything because there was no light," he said.

At least three people died in the inferno although rescuers said they were continuing their search for survivors
At least three people died in the inferno although rescuers said they were continuing their search for survivors AFP / LLUIS GENE

"I think some people were stuck inside."

Rescuers working with dogs and drones found two bodies during the night but had to stop searching when part of the building collapsed.

Badalona's conservative mayor Xavier Garcia Albiol said the authorities found at least 60 people but that many others "escaped through the back windows and fled, maybe more than 100 people".

The warehouse has been occupied for at least eight years and the authorities had tried several times to remove the squatters, he added.

Camara, who entered Spain illegally, said he couldn't get a contract that would allow him to rent a place to live because he didn't have residency papers.

"Nobody wants to live like this. We all want to rent a flat, pay social security. But if you don't have papers, how can you rent a flat?" he asked.

It is a vicious circle that has trapped many migrants, particularly from sub-Saharan Africa who scrape by as street vendors and sleep in abandoned buildings in industrial areas in and around Barcelona.

Pere Aragones, interim leader of the Catalonia region, said it was difficult to know how many people had been injured because many had fled, but pledged that those left homeless by the blaze would be helped.

"All those affected will be looked after by the social and housing services," he told Spain's TVE public television.

But the Mantero union, which supports street vendors, said the authorities were responsible for not letting migrants legalise their situation.

"We blame the authorities for denying migrants the right to decent housing and papers," the union said on Twitter.