Do you have the 3 TB Fusion Drive? If so, Apple started a replacement program for these...
"Apple has determined that a very small number of 3TB hard drives used in 27-inch iMac systems, may fail under certain conditions. These systems were sold between December 2012 and September 2013. Apple or an Apple Authorized Service Provider (AASP) will replace affected hard drives free of charge.":
https://www.apple.com/support/imac-harddrive-3tb/
I can assure you, the issue is not the power supply. I had nearly all of the iMac 27" internals replaced under Apple Care before they knew what this issue might be, including the power supply. They even replaced my 3 TB Fusion drive with another 3 TB Fusion drive (even upgrading my system to Yosemite without my permission). Within months, the problems returned... and yet again, I'm trying to back up this system to have Apple replace the 3 TB Fusion drive a second time now.
My iMac powers off instantly by itself, with no heavy load, just sitting idle. It's completely cool to the touch — the fans are not going at all. The only way it powers on after one of these episodes, is to pull the cable for at least 10 seconds, then plug it back in... to which it immediately starts up without even touching the power button. If you don't wait for 10 seconds, it does not respond to the power button at all.
I do notice it seems to power off more frequently when it accesses the 3 TB Fusion drive. It is completely incapable of doing a Time Machine backup, as the instant power offs have affected it's ability to back up. The initial backup started quickly (it was transferring hundreds of MB per second, and the progress indicator said it would take about 8 hours) — until it's first instant power off during the time machine back up. Now, backups trickle in at no more than 1 KB per second. I have 1.5 TB of data to back up, so I have to do this manually between power offs. This is by far the worst mac experience I've ever had in my life (and I've owned/used 6 macs in my lifetime). My 6 year old Mac Book Pro is more reliable than this 27" iMac... it's such a horrible situation.