Fire crews from across Somerset battled through the night to save 100 tonnes of hay.
The fire, at Middle Thrupe Farm, Maesbury, near Wells, blazed for over seven hours and could be seen in the night sky in the city.
One resident said: "I could smell smoke throughout the house and couldn't find the cause until I went outside and realised it must be a large blaze over the Mendips."
Fire services from Wells, Shepton Mallet, Street and Yeovil supplied four fire engines, a water carrier and a command support unit as they battled through the night to get the inferno under control on Thursday morning.
They jumped onto the farm's diggers to move as much of the hay from the barn before the flames could reduce them to ash.
By 3am two thirds of the hay had been moved to a field a safe distance from the burning barn.
The fire spread to adjacent farm buildings and silage stock before it was eventually contained at around 3.30am with help from pump relief units from Bridgwater, Frome and Glastonbury.
Shepton Mallet Fire Chief Graham Brown, one of the officers in charge at the scene, said that the cause of the fire was still under investigation.
He said: "The hay was only put into the barn in the seven to 10 days before the fire.
"That time period is when hay generates most heat and often internally combusts.
"The cause could either have been arson or internal combustion and investigations are on-going."