The probability distribution of the order parameter is expected to take a universal scaling form at a phase transition. In a spin system at a quantum critical point, this corresponds to universal statistics in the distribution of the total magnetization in the low-lying states. We obtain this scaling function exactly for the ground state and first excited state of the critical quantum Ising spin chain. This is achieved through a remarkable relation to the partition function of the anisotropic Kondo problem, which can be computed by exploiting the integrability of the system.