Definitely overheating then.. How old is the machine? I assume you've run all updates including any firmware updates?
You could try following a few guides on opening up the iMac and blowing it out with some compressed air..
Make sure you have the machine in a cool, well ventilated area.
Etc