The basis of musical pleasure in the brain is not clear. Here, participants’ ratings of chord pleasantness were found to be predicted by an interaction between uncertainty (lack of prior anticipation) and surprise (deviation from expectation), as quantified using a machine-learning model trained with 80,000 chord progressions. Chords were rated as more pleasant if uncertainty was low and surprise was high, or vice versa. Functional MRI revealed that this interaction modulated responses in the auditory cortex, amygdala and hippocampus.