Free-electron beams serve as uniquely versatile probes of microscopic structure and composition, and have repeatedly revolutionized atomic-scale imaging, from solid-state physics to structural biology. Over the past decade, the manipulation and interaction of electrons with optical fields has seen significant progress, enabling novel imaging methods, schemes of near-field electron acceleration, and culminating in 4D microscopy techniques with both high temporal and spatial resolution. However, weak coupling strengths of electron beams to optical excitations are a standing issue for existing and emerging applications of optical free-electron control. Here, we demonstrate phase matched near-field coupling of a free-electron beam to optical whispering gallery modes of dielectric microresonators. The cavity-enhanced interaction with these optically excited modes imprints a strong phase modulation on co-propagating electrons, which leads to electron-energy sidebands up to hundreds of photon orders and a spectral broadening of 700 eV. Mapping the near-field interaction with ultrashort electron pulses in space and time, we trace the temporal ring-down of the microresonator following a femtosecond excitation and observe the cavitys resonant spectral response. Resonantly enhancing the coupling of electrons and light via optical cavities, with efficient injection and extraction, can open up novel applications such as continuous-wave acceleration, attosecond structuring, and real-time all-optical electron detection.