At redshift z = 2, when the Universe was just three billion years old, half of the most massive galaxies were extremely compact and had already exhausted their fuel for star formation. It is believed that they were formed in intense nuclear starbursts and that they ultimately grew into the most massive local elliptical galaxies seen today, through mergers with minor companions, but validating this picture requires higher-resolution observations of their centres than is currently possible. Magnification from gravitational lensing offers an opportunity to resolve the inner regions of galaxies. Here we report an analysis of the stellar populations and kinematics of a lensed z = 2.1478 compact galaxy, which—surprisingly—turns out to be a fast-spinning, rotationally supported disk galaxy. Its stars must have formed in a disk, rather than in a merger-driven nuclear starburst. The galaxy was probably fed by streams of cold gas, which were able to penetrate the hot halo gas until they were cut off by shock heating from the dark matter halo. This result confirms previous indirect indications that the first galaxies to cease star formation must have gone through major changes not just in their structure, but also in their kinematics, to evolve into present-day elliptical galaxies.