"Fishrrman's way" to resolve partition problems is
100% guaranteed to do the job.
You will need an EXTERNAL drive large enough to hold the contents of the current Mac partition (unless you don't want to save anything on the drive).
You'll need CarbonCopyCloner, which is FREE to use for 30 days. Download it here:
www.bombich.com
What to do next:
a. Use Disk Utility to erase the external drive to Mac OS extended with journaling enabled, GUID partition format (if you're going to use Mojave or Catalina, use APFS instead)
b. Use CCC to clone the contents of the existing Mac partition onto the external drive.
c. Now, BOOT FROM the external drive. Restart, and hold down the option key CONTINUOUSLY until the startup manager appears. Select the external drive with the pointer and hit return.
d. The Mac will boot from the external drive.
e. Open Disk Utility
f. Go to the "view" menu, and if you see the option to "show all devices", choose that. (If you don't see it, don't worry about it)
g. Now click on the TOPMOST item that represents the physical drive in the iMac
h. Click the ERASE button. What you do next depends on which OS you're using (you didn't tell us)
i. If it's High Sierra or earlier, choose Mac OS extended with journaling enabled, GUID partition format. If it's Mojave or later, choose APFS, GUID partition format
j. Once you've made your choice, follow through and erase the internal drive
k. Quit Disk Utility. The internal drive is now formatted as a "single Mac partition".
l. Open CCC and "RE-clone" the contents of the backup drive BACK TO the new internal partition you just created. This may take a while.
m. Before you restart, go to the startup disk pref pane and "re-designate" the internal drive to be the boot drive
n. Now, power down, disconnect the backup, then press the power on button.
If you get a good boot, log in and look around.
Things should be "where you want 'em to be" now...