A four-month-old baby and his three-year-old brother died with their parents on Tuesday when a fire ripped through an abandoned bank where the family was squatting in Barcelona, in a blaze denounced as "horrific" by the Spanish city's mayor.

Chief firefighter Angel Lopez said the alarm was raised at around 6:00 am (0500 GMT) by a witness who spotted the fire in a former bank building in the central Plaza de Tetuan.

It was only while they were battling the fire that they realised there were four people inside: "two adults, a baby and a three-year-old boy", Lopez said.

Four other people were rescued and taken to hospital for smoke inhalation Four other people were rescued and taken to hospital for smoke inhalation Photo: AFP / Pau BARRENA

"Emergency services tried to revive them, but they couldn't save them."

The couple, a 40-year-old man and his 39-year-old partner, used to collect scrap metal, Barcelona city hall said, saying the children were two boys, one aged three, the other just four months.

According to La Vanguardia newspaper, he was from Pakistan and she was Romanian.

Map of Barcelona Map of Barcelona Photo: AFP / Paz PIZARRO

"There are no words to describe the horror of four people dying, among them two very young children, this is something that should never have happened... It is horrible news," Barcelona mayor Ada Colau told reporters at the scene, herself a former activist against evictions.

Neighbours who lived in a flat above the premises which was not harmed in the fire, said they could hear the family screaming for help.

"My wife smelled something burning, we got up and saw nothing but when we went to the place where we keep the washing machine, there was a huge amount of smoke," said Miquel Guimera.

Four other people were rescued and taken to hospital for smoke inhalation Four other people were rescued and taken to hospital for smoke inhalation Photo: AFP / Pau BARRENA

"Downstairs in the squat they were screaming for help, because they were locked in. It was quite traumatic," he said, indicating the family had been living in the squat for two or three years.

"It's a real shame about those two little children."

The aftermath of a fire in an abandoned Barcelona building that left four people dead, including a baby and a toddler The aftermath of a fire in an abandoned Barcelona building that left four people dead, including a baby and a toddler Photo: AFP / Pau BARRENA

Four men who had run into a courtyard to escape the flames were rescued and taken to hospital for smoke inhalation, Lopez said.

The Mossos d'Esquadra regional police have opened an investigation into the fire, which took place in a lively middle-class residential neighbourhood in the heart of Barcelona.

By sunrise, the building -- with its former sign blacked out and its facade spray painted with graffiti -- was cordoned off with emergency vehicles parked outside as rescuers came and went.

Colau said social workers knew the premises and had been there to offer food handouts to the occupants along with information on how to get medical care.

"Behind this tragedy was a situation of poverty, social exclusion and homelessness that was quite complex to manage as a city council," said Laura Perez, one of the Barcelona's senior social rights officials.

She said the family had been receiving support from city hall since August 2020 and the three-year-old was in school.

Hours before the fire broke out, police were called to the building because of a dispute but there was no immediate evidence it was related to the blaze, regional interior minister Joan Ignasi Elena told reporters.

Josep Iganci Homs, a 77-year-old pensioner, said he was often awoken at night by sounds of shouting and fighting inside the premises.

"The authorities and the courts should have removed the children from here because look at how it all ended," he told reporters while gazing at the blackened building.

With housing prices sky high, some 481 people are currently living in 105 squats around the city, among them 156 minors. Another 384 live in informal camps, city figures say.

Another 20 people were hurt when they jumped out of windows to escape the flames and choking smoke.