Possibly a power supply fault
I had a similar problem on my iMac.
If you run dmesg from Terminal after restarting the machine you may see a short message and/or an error number. A search of the apple support site with the error number showed the problem to be related to the power supply. If you're feeling brave you can also wade you way through the logs in /var/log.
I'm not guaranteeing The power supply is your problem but the system error logs are a good place to start for mysterious problems. There may be an easier way to see the system errors other than dmesg but I live in console land and skipped the GUI bit of the manual.
BTW: Apple replaced my power supply for free even though my machine was out of warranty, apparently there was a faulty batch produced around 4 to 5 years ago.