Surveys have revealed many multi-planet systems containing super-Earths and Neptunes in orbits of a few days to a few months1. There is debate whetherin situassembly2or inward migration is the dominant mechanism of the formation of such planetary systems. Simulations suggest that migration creates tightly packed systems with planets whose orbital periods may be expressed as ratios of small integers (resonances)3,4,5, often in a many-planet series (chain)6. In the hundreds of multi-planet systems of sub-Neptunes, more planet pairs are observed near resonances than would generally be expected7, but no individual system has hitherto been identified that must have been formed by migration. Proximity to resonance enables the detection of planets perturbing each other8. Here we report transit timing variations of the four planets in the Kepler-223 system, model these variations as resonant-angle librations, and compute the long-term stability of the resonant chain. The architecture of Kepler-223 is too finely tuned to have been formed by scattering, and our numerical simulations demonstrate that its properties are natural outcomes of the migration hypothesis. Similar systems could be destabilized by any of several mechanisms5,9,10,11, contributing to the observed orbital-period distribution, where many planets are not in resonances. Planetesimal interactions in particular are thought to be responsible for establishing the current orbits of the four giant planets in the Solar System by disrupting a theoretical initial resonant chain12similar to that observed in Kepler-223.