I suspect that the black screen mislead you think that the power stops. You can check whether your iMac connects to the power source and is charged well. Perhaps, there's something wrong with your power socket or the power cord, making a power failure from time to time.
If you ensure that's not the case, try these solutions to fix your Mac that won't boot up:
- Reset NVRAM. This can exclude the errors in macOS-related settings that result in your iMac not turning on.
- Reset SMC. This is to drive away the issues about the power-related settings that stop your iMac to receive the power for booting up.
- Do a hard restart. Press the power button for about 10 secs and wait a moment, then press the power button to restart your Mac.
- Boot into Recovery Mode. macOS Recovery Mode can give you some utilities to repair your unbootable Mac. In Recovery Mode, you can run First Aid in Disk Utility to check the startup disk. If that helps nothing, you can also try reinstalling macOS.
If the above ways fail to make your iMac boot up, you need to contact a repair service. By the way, since your Mac won't turn on, you'd better rescue files on it with a professional data recovery tool in case of permanent data loss. Here, iBoysoft Mac Recovery Mode is recommended to you. This special mode supports recovering data from an unbootable Mac quickly and easily.