The blast in Arganda del Rey sent up a huge column of black smoke, but emergency services said several air quality measuring stations in the area showed normal readings, easing concerns about toxic pollution.
Madrid's emergency services centre said on Twitter there had been "several explosions" at the site which seriously injured three people, "two with burns and one with a broken pelvis".
A spokesman for the firefighters told AFP that another 27 were hurt to a lesser degree.
The spokesman said authorities were investigating the cause of the explosion, about 30 kilometres (20 miles) southeast of the Spanish capital.
More From This Section
The emergency services centre added that several schools near the blaze -- which firefighters were still working to extinguish -- had been evacuated.
"Neighbours have been asked not to leave their homes and to keep windows closed," a spokesman for Arganda del Rey's city hall told AFP, emphasising however that air quality was "normal".
Requimsa, the company that owns the site, "manages and collects all types of hazardous waste", according to its website.