DSP Muthukumar said the fire broke out while they were mixing chemicals for some crackers which exploded.
The deceased have been identified as Ramakrishnan (38) and Gurusamy (61), police said.
The shed where they were working was gutted while 20 others who were trapped in the factory were rescued by fire service personnel who doused the fire.
The factory was working under a licence issued by the controller of explosives.
The owner of the factory Jayasankar and foreman are absconding, police said.