Chosen Solution

Where do i start, My iMac (2008) does the same (shutting down and back on again) I have changed the power chord and delved in and changed the power supply, that did nothing !!! I wiped the drive clean and a fresh install, nothing happened, so I put a new HDD in, and still the problem keeps happening :( Changed the RAM, still no fix, so I’m only left with changing the logic board !!! But after all that I’ve done, I don’t think I can be bothered !!! Update (03/22/2018) Well ……… I have just bought the logic board and I will be back with an update to tell you if it has fixed the problem Update (03/22/2018) So, the logic board arrived, I had to put the graphics card from the old board on to the one that arrived as it did not come with it and then installed the logic board and …. It fixed the problem of randomly switching off and on, its running like a brand new iMac !!! I just wished I done that in the first place lol

You still have an underlying problem here! You really need to check your buildings/house wiring and get a surge suppressor or UPS