Have you tried to boot your Mac into Recovery Mode? There's a chance for you to recover data from your bad iMac hard drive. The prerequisite is that your Mac can enter Recovery Mode.
To enter macOS Recovery Mode, you can start up your Mac and meanwhile press down the Command + Option + R keys together.
If your iMac can enter macOS Recovery, it means that the internal hard drive only has some software issues. In that case, you can use iBoysoft Mac Recovery Mode to rescue files from your bad hard drive.
If you fail to boot your Mac into Recovery Mode, it indicates that your hard drive is physically damaged. You need to take it to a data recovery lab to try to get back the files.