Periods of slow heart rate are associated with increased sensory sensitivity. Accordingly, cardiac deceleration occurs when individuals orient their attention in anticipation of a sensory stimulus they might have to respond to (attentive anticipation). Cardiac deceleration might be important to optimize sensory processing. However, it is unclear which mechanism connects heart rate with the neuronal processing of external stimuli.In this study, we investigated if cardiac deceleration evoked by attentive anticipation as well as ongoing fluctuations in heart rate were associated with changes in the heartbeat-evoked potential (HEP), a cortical response evoked by the heartbeat which amplitude modulations are associated with sensory sensitivity. We studied these phenomena in young and older people [N = 33 (26 women) and 29 (23 women); mean age 23 and 61 years], using a previously described dataset including electroencephalograms (EEG), electrocardiograms (ECG), and pupilograms which were acquired during an auditory cued simple reaction time task, an auditory cued go/no-go task, and a passive task condition.While the period of attentive anticipation between the cue and the target characterized by cardiac deceleration was not related with significant changes in the HEP, ongoing heart rate fluctuations affected HEP amplitude. Interestingly, the effect of heart rate on the HEP increased with task difficulty and was associated with the amplitude of task-related pupil responses suggesting a link with mental effort.Thus, the impact of ongoing heart rate fluctuations on the HEP depends on cognitive state and this effect might link heart rate with the neural processing of external stimuli.SIGNIFICANCE STATEMENTThese findings suggest that arousal level and mental effort modulate the input-output function that links heart rate to the strength of the cortical responses to the heartbeat. As such, the modulation of the heartbeat-evoked potential by heart rate emerges as a marker of cortical gain that is relatively easy to measure non-invasively in humans. Further studies should explore if this effect of mental effort extends to other sensory modalities, for example, the visual cortex neuronal gain. Moreover, this study suggests that the effect of heart rate on the neuronal processing of external stimuli is stronger during periods of high mental effort, raising a new hypothesis which exploration will further elucidate the connection between the heart and cognitive processing.