Firefighters work to extinguish the fire in a 24-storey building used by squatters that later collapsed in Sao Paulo, Brazil, the largest city in Latin America

A 24-storey building used by squatters in the center of Sao Paulo, Brazil's biggest city, collapsed early Tuesday after a blaze that tore through the structure, leaving at least three missing.

Survivors described waking in the night to find themselves surrounded by flames and escaping with their children before the tower turned to rubble.

Scores of homeless families were occupying the building, according to officials. However, despite the ferocity of the blaze, only one person was listed as almost certainly dead.

"There are some missing, approximately three, with one very likely a fatality," Ricardo Peixoto, a firefighters' commander, told AFP. "We don't know how many people were in the building so we don't know whether we'll find more victims in the ruins."

So far, 250 people who'd been living in the building have been registered after the blaze, city security official Jose Roberto said.

The fire began overnight and spread rapidly, turning the building into an inferno before it fell down.

Dramatic pictures tweeted by the fire service showed flames shooting up the sides of the whole tower, moments before it was reduced to a heap of smoking ruins. An adjacent church was also damaged.

"We got the call at around 1:30 am (0430 GMT) and we came at once, a few minutes later, and about five floors of the building were on fire," Peixoto said. "Fifteen or 20 minutes later the building fell."

Fifty-seven vehicles and 160 firefighters were deployed to the scene, the department said.

- Frantic escape -

Sao Paulo is Brazil's financial capital and the most populous city in Latin America, but suffers huge economic inequality.

Poor families often squat in disused buildings or set up tents and shacks on vacant land, sometimes next to wealthy areas.

President Michel Temer, who is Brazil's most unpopular leader on record, with single-digit approval ratings, got a hostile reception when he briefly visited the scene.

"We want housing!" a crowd chanted.

One survivor, 26-year-old Henrique, said he managed to get out from the third floor with his girlfriend and their dog.

"We woke and the building was already on fire," he said. "We struggle so much and now we've lost everything."

Another man, Jose Antonio, described the frantic escape from the sixth floor, where he lived with his wife, three children and sister-in-law.

"I was unsure if my son had taken my youngest daughter," Antonio, 48, told AFP. "There was still time to go back so I returned, I looked around, I patted the mattresses. There wasn't time to take anything. I patted the mattresses, saw no one was at home anymore, then I went down behind them shouting their names to see if they had gone down."

Sao Paulo state Governor Marcio Franca said "it was a tragedy waiting to happen.... This building didn't have even the minimum conditions for habitation. The state should not have allowed it to be occupied."

From a safety point of view, the building was a ticking bomb, Peixoto said.

"There was no security, there were not adequate electrical installations, there were no safe staircases, there were piles of rubbish -- there was everything you need to start a major fire," he said.

Firefighters work to extinguish the fire in a 24-storey building used by squatters that later collapsed in Sao Paulo, Brazil, the largest city in Latin America

Sao Paulo suffers from huge inequality, and poor families often squat in disused buildings such as this one which caught fire and collapsed, likely leaving one person dead