BADALONA, Spain- Flames ripped through an abandoned warehouse occupied by scores of immigrant squatters in a Barcelona suburb, killing at least three people and injuring at least 23.

"It's possible that more victims could be found," Miquel Samper, in charge of interior affairs in the regional Catalan government, told reporters at the site.

The fire, which broke out late on Wednesday sending a huge cloud of smoke into the air, was under control by Thursday morning, but authorities said parts of the building had collapsed and there was a risk the whole structure could fall.

"I looked out and saw the building burning, it looked like the Colossus on fire. From home we can see everything, we saw how some people jumped from the windows," Calixto Palomares, 71, who witnessed the fire, told Reuters.

Firefighters have only been able to search half of the warehouse, Samper said. Firefighters plan to use drones and dogs to inspect the most dangerous areas of the building.

Spain's Prime Minister Pedro Sanchez offered his condolences. Speaking before the third death was announced, he described the first two dead as north African immigrants. Regional officials have not commented on the victims' nationality.

The origin of the fire was not yet known.

Undocumented immigrants often slept in the warehouse in the large industrial suburb of Badalona, Catalonia's acting president Pere Aragones and other officials said.

"It was a squat which we had for years known could end in tragedy," said Badalona Mayor Xavier Garcia Albiol.

Many people who were sleeping inside managed to escape, but it was unclear if anyone else remained trapped, Aragones told broadcaster TVE.

The building had housed as many as 180 people in the past, a Catalan interior department spokesman said.

Emergency services treated 23 people, including three in a critical state and four others seriously injured, officials said.

Badalona is a large coastal suburb of Barcelona with a population of about 220,000, making it the fourth largest city in the Catalonia region.

(Reporting by Albert Gea, Jordi Rubio and Luis Felipe Castilleja in Badalona, Joan Faus in Barcelona and Inti Landauro, Ingrid Melander and Nathan Allen in Madrid Writing by Ingrid Melander Editing by Andrei Khalip and Peter Graff) ((Inti.Landauro@thomsonreuters.com;))