Had 24" iMac that exhibited the same symptoms. Diagnosed with bad logic board by respectable shop.
open