The company owners said the containers in Santos were full of acid and a disinfectant which came into contact with rainwater, causing a reaction.
The area's mayor said at least 66 people were taken to hospital with breathing difficulties.
Officials said the fire had been controlled but that there is still smoke in the area.
The cargo terminal and nearby homes were evacuated and residents were asked to stay inside.
The container terminal was operated by Localfrio, a logistics company, in Guaruja, an area on the eastern side of Santos, in Sao Paulo state.
A spokeswoman for the company, which exports chemicals used for refrigeration and general cargo, said the containers were filled with chloric acid and sodium dichloroisocyanurate - a cleaning and disinfectant agent.
Firefighters said rainwater had seeped into the containers causing a chemical reaction.
Local Mayor Mario Antonieta de Brito asked people to stay out of the rain which could "contain chemical elements that can burn the skin".
This is the latest in a series of recent incidents involving chemical companies in Brazil:
A chemical explosion at a cargo warehouse in Brazil has spread toxic gas over the country's biggest port.