We investigate the statistics of the fluctuations of the energy transfer between an overdamped Brownian particle, whose motion is confined by a stationary harmonic potential, and a surrounding viscoelastic fluid at constant temperature. We derive an analytical expression for the probability density function of the energy exchanged with the fluid over a finite time interval, which implicitly involves the friction memory kernel that encodes the coupling with such a non-Markovian environment, and reduces to the well known expression for the heat distribution in a viscous fluid. We show that, while the odd moments of this distribution are zero, the even moments can be explicitly expressed in terms of the autocorrelation function of the particle position, which generally exhibits a non-mono-exponential decay when the fluid bath is viscoelastic. Our results are verified by experimental measurements for an optically-trapped colloidal bead in semidilute micellar and polymer solutions, finding and excellent agreement for all time intervals over which the energy exchange takes place.