The collective behaviour of a many-body system near a continuous phase transition is insensitive to the details of its microscopic physics; for example, thermodynamic observables follow generalized scaling laws near the phase transition1. The Berezinskii–Kosterlitz–Thouless (BKT) phase transition2, 3 in two-dimensional Bose gases presents a particularly interesting case because the marginal dimensionality and intrinsic scaling symmetry4 result in a broad fluctuation regime and an extended range of universal scaling behaviour. Studies of the BKT transition in cold atoms have stimulated great interest in recent years5, 6, 7, 8, 9, 10, but a clear demonstration of critical behaviour near the phase transition has remained elusive. Here we report in situ density and density-fluctuation measurements of two-dimensional Bose gases of caesium at different temperatures and interaction strengths, observing scale-invariant, universal behaviours. The extracted thermodynamic functions confirm the existence of a wide universal region near the BKT phase transition, and provide a sensitive test of the universality predicted by classical-field theory11, 12 and quantum Monte Carlo calculations13. Our experimental results provide evidence for growing density–density correlations in the fluctuation region, and call for further explorations of universal phenomena in classical and quantum critical physics.