With older iMacs, the problem is most likely due to a failing Hard Drive, but an issue with third party software is also a possibility.
You can try booting into Safe Mode to see if that makes a difference. If this works, then most likely the issue is due to an issue with third party installed software, or possibly a file system issue, or even a drive failure is still possible since Safe Mode may be bypassing the troubled file on the bad section of the drive.
You can try running the Apple Diagnostics to see if any hardware issues are detected. Unfortunately the diagnostics rarely detect problems even when a hardware issue is confirmed to exist through other methods.
What is the exact model of this iMac? You can get this information by entering the system serial number on the check coverage page here (please do not post the serial number on the forum since it is considered personal information):
Check Your Service and Support Coverage - Apple Support
If you have a spare external drive you can try installing macOS onto the external drive to see if the iMac will boot from the external installation of macOS. If so, it will tell you the issue is most likely due to the internal drive (hardware or software), plus it gives you more options for trying to determine which it is.