Loosen the three Phillips screws securing the rear panel to the iMac.
These screws are captive in the iMac. The center screw will stop turning after about 3.5 turns and the outer screws will stop turning after about 5.5 turns. Do not try to remove these screws from your iMac.
Lift the optical drive near the connector to separate it from the logic board.
Lift the free end of the optical drive just enough to clear the fan cover. Lifting the free end of the optical drive too far may break the plastic positioning pins off the front bezel.
Lift the free end of the optical drive slightly, then pull it away from the edge of the rear case to clear the two plastic positioning pins.
Lift the optical drive out of your iMac.
When reinstalling your optical drive it may be necessary to set the bezel attached to the open end of the drive on the plastic positioning pins molded into the front bezel of the iMac and pull the connector side of the drive toward the edge of the rear case, bending it outward slightly, to properly seat the connector.
Working from alternating sides of the board, use the flat end of a spudger to separate the optical drive connector board from the optical drive.
The socket in the optical drive is particularly deep, so don't pry the connector up too far from one side to avoid shearing the connector off the board.