There were no immediate reports of deaths in Diogo Pires, a small shantytown in western Sao Paulo that is home to about 300 families.
Two people sought medical treatment for smoke inhalation, according to fire officials.
Television broadcasts showed flames leaping 20 meters (65 feet) into the air as some residents fled and others helped firefighters battle the blaze with hoses and buckets of water.
"The flames were huge. People screamed and quickly ran out of the community," resident Ana Paula Martiniano told Globo television.
Fire officials said they did not know what caused the blaze, which began around 6 p.m. (2100 GMT).
Two hours after it began, firefighters managed to contain the flames to an area about 1 square kilometer (a square half-mile).
They also kept it from spreading to neighboring industrial buildings containing drums of combustible chemicals.