The measurement of the cosmic microwave background has strongly constrained the cosmological parameters of the Universe. When the measured density of baryons (ordinary matter) is combined with standard Big Bang nucleosynthesis calculations, the amounts of hydrogen, helium and lithium produced shortly after the Big Bang can be predicted with unprecedented precision. The predicted primordial lithium abundance is a factor of two to three higher than the value measured in the atmospheres of old stars. With estimated errors of 10 to 25%, this cosmological lithium discrepancy seriously challenges our understanding of stellar physics, Big Bang nucleosynthesis or both. Certain modifications to nucleosynthesis have been proposed, but found experimentally not to be viable. Diffusion theory, however, predicts atmospheric abundances of stars to vary with time, which offers a possible explanation of the discrepancy. Here we report spectroscopic observations of stars in the metal-poor globular cluster NGC 6397 that reveal trends of atmospheric abundance with evolutionary stage for various elements. These element-specific trends are reproduced by stellar-evolution models with diffusion and turbulent mixing. We thus conclude that diffusion is predominantly responsible for the low apparent stellar lithium abundance in the atmospheres of old stars by transporting the lithium deep into the star.