The cause of the blast at the factory on the outskirts of the city near the airport was unknown.
The explosion at the factory, which makes fireworks and matches, was heard in a large area of the city. Television pictures showed a large column of smoke rising from the factory.
Emergency services urged local residents to stay away from the area. The airport continued operating.
A spokeswoman for the regional government of Aragon said five people were killed in the blast.
“As well as the deaths, at the moment there are six people injured to varying degrees,” she said.
She said firefighters were continuing their work at the factory, which exports products to other European countries and Canada.
El Pais newspaper said accidents at fireworks factories around Spain in the last 25 years had claimed more than 110 lives.