If you haven't already try resetting the SMC and the NVRAM (PRAM) on your device.
Next try booting into safe mode (safe boot) and then try to restart the Mac afterwards and see if that helps.
Safe mode (sometimes called safe boot) is a way to start up your Mac
so that it performs certain checks and prevents some software from
automatically loading or opening. Starting your Mac in safe mode does
- Verifies your startup disk and attempts to repair directory issues, if needed loads only required kernel extensions
- Prevents startup items and login items from opening automatically
- Disables user-installed fonts
- Deletes font caches, kernel cache, and other system cache files
Perhaps reinstalling macOS via macOS Recovery can help.
Also depending on your model and year of iMac, you may be able to upgrade the amount of memory in it and possibly double the current amount.