When a metal undergoes a continuous quantum phase transition, non-Fermi liquid behaviour arises near the critical point. It is standard to assume that all low-energy degrees of freedom induced by quantum criticality are spatially extended, corresponding to long-wavelength fluctuations of the order parameter. However, this picture has been contradicted by recent experiments on a prototype system: heavy fermion metals at a zero-temperature magnetic transition. In particular, neutron scattering from CeCu$_{6-x}$Au$_x$ has revealed anomalous dynamics at atomic length scales, leading to much debate as to the fate of the local moments in the quantum-critical regime. Here we report our theoretical finding of a locally critical quantum phase transition in a model of heavy fermions. The dynamics at the critical point are in agreement with experiment. We also argue that local criticality is a phenomenon of general relevance to strongly correlated metals, including doped Mott insulators.