Early-type galaxies are considered to be the end products of massive galaxy formation1. Optical spectroscopic studies reveal that massive early-type galaxies formed the bulk of their stars over short timescales (≲?1 Gyr) and at high redshift (z ≳? 2), followed by passive evolution to the present2. However, their optical spectra are unable to constrain small episodes of recent star formation, since they are dominated by old stars. Fortunately, this problem can be tackled in the ultraviolet range. While recent studies that make use of ultraviolet absorption lines have suggested the presence of young stars in a few early-type galaxies3, the age and mass fractions of young stars and their dependence on galaxy mass are unknown. Here we report a detailed study of these young stellar populations, from high-quality stacked spectra of 28,663 galaxies from the BOSS survey4, analysing optical and ultraviolet absorption lines simultaneously. We find that residual star formation is ubiquitous in massive early-type galaxies, measuring average mass fractions of 0.5% in young stars in the last 2 Gyr of their evolution. This fraction shows a decreasing trend with galaxy stellar mass, consistent with a downsizing scenario5. We also find that synthetic galaxies from state-of-the-art cosmological numerical simulations6 substantially overproduce both intermediate and young stellar populations. Therefore, our results pose stringent constraints on numerical simulations of galaxy formation6,7.