The fire, one of the country’s worst industrial disasters in recent years, happened as the factory was rushing to fulfill a military contract, the authorities said.