What I'd try:
SMC reset (if your iMac has it).
If that doesn't work...
Try RE-installing the OS.
(I realize it's a pain, but try it anyway).
Before you do that...
Can you try "a safe boot" (boot and hold down the shift key CONTINUOUSLY).
Just something to try. Can you see the drives after a safe boot?
You didn't tell us WHICH iMac you have and WHAT YEAR it was made.
Can you boot to INTERNET recovery?
Command-OPTION-R
at boot.
Once the internet utilities are loaded, you can open disk utility.
It should be able to "see" the ports (and connected drives).
Don't do anything to them, you're "just looking".
Can you see them?