Heat dissipation in integrated nanoscale devices is a major issue that requires the development of nanoscale temperature probes. Here, we report the implementation of a method that combines electron energy gain and loss spectroscopy to provide a direct measurement of the local temperature in the nanoenvironment. Loss and gain peaks corresponding to an optical-phonon mode in boron nitride were measured from room temperature to ̃1600 K . Both loss and gain peaks exhibit a shift towards lower energies as the sample is heated up. First-principles calculations of the temperature-induced phonon frequency shifts provide insights into the origin of this effect and confirm the experimental data. The experiments and theory presented here open the doors to the study of anharmonic effects in materials by directly probing phonons in the electron microscope.