I have a problem with my iMac restarting when it should be shutting down. This doesn't happen all the time but appears to happen more frequently when I've had the computer on for a few hours.
- I shut the computer down via Apple Menu > Shut Down
- The shut down cycle completes
- The computer immediately reboots
It doesn't behave like this Mac OS X never shuts down. The Mac responds to being shut down immediately.
Fixes I've tried
First I should state I've pulled out all USBs etc. The only wire in is the power cable.
I've been in touch with Apple Support about this issue, and the only advice they could give was to run First Aid in the Disk Utility. Sometimes this allows me to shut down. Other times not.
Resetting the SMC
I've reset the SMC which doesn't help. This often leads to another issue which is freezing on reboot (Apple logo and progress bar that doesn't move). To fix this I reset the PRAM/VRAM
Reset the PRAM/VRAM
Resetting the PRAM allows me to shut down most of the time. Even then I have to do it 2 or 3 times before it works.
I've also reinstalled the system twice, one time upgrading from El Capitan to Sierra. This has temporarily fixed the issue, but it soon comes back after a week or so.
iMac (27-inch, Late 2013)
3.4 GHz Intel Core i5
6 GB 1600 MHz DDR3
NVIDIA GeForce GTX 775M 2048 MB
macOS Sierra 10.12.5
EDIT: Current Energy Saver Settings
I'd really appreciate your help here guys, this has been going on a while and it's becoming a bit of a nuisance.
EDIT: This question appears to highlight a pretty common occurrence. I'm happy to invest more into the bounty to get an answer that resolves or at least identifies the problem causing it to happen.
After going through the steps in the answer provided by @monomeeth, Apple Diagnostics uncovered an error
NDT001: There may be an issue with the Thunderbolt hardware. I've run Diagnostics before, but this time I ran it straight after the Mac restarted from a failed shut down. I'll be taking it into Apple for repair, so I'll keep this answer up to date with the outcome.