Detecting weak radio-frequency electromagnetic fields plays a crucial role in a wide range of fields, from radio astronomy to nuclear magnetic resonance imaging. In quantum optics, the ultimate limit of a weak field is a single photon. Detecting and manipulating single photons at megahertz frequencies presents a challenge because, even at cryogenic temperatures, thermal fluctuations are appreciable. Using a gigahertz superconducting qubit, we observed the quantization of a megahertz radio-frequency resonator, cooled it to the ground state, and stabilized Fock states. Releasing the resonator from our control, we observed its rethermalization with nanosecond resolution. Extending circuit quantum electrodynamics to the megahertz regime, we have enabled the exploration of thermodynamics at the quantum scale and allowed interfacing quantum circuits with megahertz systems such as spin systems or macroscopic mechanical oscillators.