After desperately searching for a solution to the Debian install on my old 2012 iMac not producing sounds through the headphone jack connected speakers, this provided the solution:
To fix this problem, you have to load snd-hda-intel module with model=imac27_122 option.
To do this, create a new file in /etc/modprobe.d (for example /etc/modprobe.d/sound.conf) with following content:
options snd-hda-intel model=imac27_122
Reboot and headphones will work as expected.