It is probably the capacitors on the logic board that is causing this. It was a common issue with the G5 iMacs, and causes symptoms like this. The easiest way to check if this is the issue is opening up the iMac and looking at the logic board for caps that have "exploded" like the attached picture. If this is the case, then you will have to order new caps and replace them yourself.