White dwarfs are stellar embers depleted of nuclear energy sources that cool over billions of years1. These stars, which are supported by electron degeneracy pressure, reach densities of 107 grams per cubic centimetre in their cores2. It has been predicted that a first-order phase transition occurs during white-dwarf cooling, leading to the crystallization of the non-degenerate carbon and oxygen ions in the core, which releases a considerable amount of latent heat and delays the cooling process by about one billion years3. However, no direct observational evidence of this effect has been reported so far. Here we report the presence of a pile-up in the cooling sequence of evolving white dwarfs within 100 parsecs of the Sun, determined using photometry and parallax data from the Gaia satellite4. Using modelling, we infer that this pile-up arises from the release of latent heat as the cores of the white dwarfs crystallize. In addition to the release of latent heat, we find strong evidence that cooling is further slowed by the liberation of gravitational energy from element sedimentation in the crystallizing cores5-7. Our results describe the energy released by crystallization in strongly coupled Coulomb plasmas8,9, and the measured cooling delays could help to improve the accuracy of methods used to determine the age of stellar populations from white dwarfs10.