I've had this problem twice in 3 years with my iMac. Fiirst fix was to replace the headphone board inside computer. The most recent failure(this week) was still covered under AppleCare.
I was expecting the same"fix", replace Audio I/O Cable board...well the replacement part was ordered and installed and I'm being told that this still does not solve problem. Now they think my exterior case is "warped" and a new one needs to be ordered and installed.
This seems very drastic to me. I looked at audio jack at back of iMac and it appears that the earphone jack receptical does not aligined perfectly with the drilled holed in the aluminum casing. I'm thinking there has to be an easier way to make this work...any ideas?