From The ultimate guide to ejecting a stuck disc from Mac SuperDrive
Launch Disk Utility (Applications > Utilities) and select the troublesome CD or DVD in the sidebar. Click the Eject button at the top of the window.
Launch Terminal (Applications > Utilities) and copy the following command:
Restart your Mac and hold down the left mouse button (or trackpad if you have a laptop) as it boots up. Keep pressing it until the login screen or desktop displays.
Tilt and shake
Pick up your Mac laptop and tilt it so the CD/DVD drive is pointing downwards. Restart and hold the Eject key down while gently shaking the computer up and down.
The self-fixing Mac
Shut down your Mac, turn it back on, and let it sit for 10-15 minutes. Make sure the power cord is plugged in as you do this and the disc just might pop out on its own.
Disrupt the spin
If you listen carefully, you can probably hear your optical drive powering up & down over and over again. As long as the disc spins, it’s not coming out. The first step is to get your hands on a very thin piece of cardboard or even a folded business card (so it’s twice as thick). Now restart your Mac and hold down the mouse/trackpad button as you poke the cardboard inside the SuperDrive slot. The goal is to slip it above the CD or DVD — towards the left side of the drive — and gently jiggle it around to put pressure on the disc. You might have to continue this for up to a minute or so, but it often works when all other methods fail.
Tilt-and-shake probably isn't a good idea with an iMac and you've tried holding the mouse button on reboot, but the rest seem worth a shot.