Mac automatically restarts after shutdown I was using Win 10 on my 2017 21.5" iMac before, but formatted it and installed Mac Mojave again. Here format means I've formatted the data disk as well as system disk, merged all partitions and make only one volume. And installed Mojave.

Now if I select "Shutdown" in the Finder menu the Mac always automatically restarts instead. I am using power button to shutdown the computer. Sometimes, the computer restarts itself - without any action. Weird.

How can I fix or diagnose this?
I used to work as an Apple technician and I'v had several Macs that describe your issue, but they were only laptops. The issue with them was liquid damaged. Now you thinking how the h'll can an iMac get liquid damaged, but I can tell you, I'v actually seen it myself. So it's possible but maybe not in your case.

I recommend to let an Apple technician look at it. Water damage causes a fault in the circuitry, but the same fault can happen from other causes or just rare breakage.