The blaze at the Edrington Group's site in Glasgow in June 2011 happened when liquid hit a light fitting as casks were being filled with whisky.
An investigation by the Health and Safety Executive (HSE) found that the lights should not have been used in a flammable atmosphere.
The company has now been fined at Glasgow Sheriff Court after earlier admitting breaking health and safety at work laws.
Two workers were on a metal walkway at the top levels of the warehouse, which is in Great Western Road, using flexible hoses to fill 450-litre casks with whisky pumped from steel vats, the court heard.
One of them said he felt the hose relax before a jet of whisky shot up towards a light fitting above a forklift truck. It hit the light fitting and a flame engulfed the cage of the forklift truck, the HSE said.
Both men ran towards the stairs at the back of the warehouse, setting off the fire alarm as they left, prompting the evacuation of the whole site.
It was later discovered that 70 of the 110 sprinkler heads in the warehouse were activated.
HSE inspectors said the two workers were "extremely lucky" not to have been killed or seriously injured.
Their investigation found that the central aisle lights in the warehouse should not have been used and had they been checked, they would have been identified as an ignition-source risk.
The filling equipment was not suitable for use to transfer a hazardous substance like alcohol at pressure, inspectors also said.
After sentencing, HSE inspector David Stephen said: "This was a major incident that could have had disastrous consequences. The two workers had to run for their lives and were extremely lucky not to have been killed or seriously injured.
"More than 17,500 litres of whisky were lost during the incident. This volume of flammable liquid could have served as fuel for a significant fire, which would have caused major disruption and damage to the environment.
"Had the company taken the simple steps of checking the light fittings were suitable for use in a flammable atmosphere and that the equipment used to transfer the alcohol was fit for purpose, this incident could have been prevented.
"Since the incident, the filling of whisky casks in this way at the premises has been made redundant with the introduction of a new tank facility in October 2011."
During a hearing last week Edrington Group pleaded guilty to breaking section 2 of the Health and Safety at Work Act 1974.
A spokesman said: "Edrington can confirm that it was fined £40,000 today as a result of an isolated incident at its Great Western Road Glasgow site in June 2011.
"The company took full responsibility for this incident from the outset and co-operated immediately and fully with both the HSE and the Scottish Environment Protection Agency. Edrington takes the health and safety of its employees extremely seriously.
"Following an investigation, new procedures were introduced, culminating in the introduction of a new filling facility that became operational in October 2011.
"Edrington has an excellent health and safety record and remains committed to continually improving its health and safety systems. In the last five years Edrington has spent approximately £1.5 million on health and safety improvements."