If it only occasionally does this then run Disk Utility (and then the First said option) first to see if that solves anything, then make a bootable backup to an external drive. (If the problem is the internal drive you can then boot from the external drive and ignore the internal and keep on truckin’.)
Did you try restarting in Safe mode? If that works, once again try running Disk Utility and the First Aid option.
If the Mac simply won’t finish booting it could be the drive or something corrupted in macOS or something in hardware and if you don’t have a bootable USB stick or external drive you’ll likely need a repair shop to look at it.
My 2010 iMac runs fine, but the original HD was replaced in 2016 with an SSD and second internal HD (where the CD drive used to be). Well worth doing if you want to save $1.5k.