Haumea-one of the four known trans-Neptunian dwarf planets-is a very elongated and rapidly rotating body. In contrast to other dwarf planets, its size, shape, albedo and density are not well constrained. The Centaur Chariklo was the first body other than a giant planet known to have a ring system, and the Centaur Chiron was later found to possess something similar to Chariklo's rings. Here we report observations from multiple Earth-based observatories of Haumea passing in front of a distant star (a multi-chord stellar occultation). Secondary events observed around the main body of Haumea are consistent with the presence of a ring with an opacity of 0.5, width of 70 kilometres and radius of about 2,287 kilometres. The ring is coplanar with both Haumea's equator and the orbit of its satellite Hi'iaka. The radius of the ring places it close to the 3:1 mean-motion resonance with Haumea's spin period-that is, Haumea rotates three times on its axis in the time that a ring particle completes one revolution. The occultation by the main body provides an instantaneous elliptical projected shape with axes of about 1,704 kilometres and 1,138 kilometres. Combined with rotational light curves, the occultation constrains the three-dimensional orientation of Haumea and its triaxial shape, which is inconsistent with a homogeneous body in hydrostatic equilibrium. Haumea's largest axis is at least 2,322 kilometres, larger than previously thought, implying an upper limit for its density of 1,885 kilograms per cubic metre and a geometric albedo of 0.51, both smaller than previous estimates. In addition, this estimate of the density of Haumea is closer to that of Pluto than are previous estimates, in line with expectations. No global nitrogen- or methane-dominated atmosphere was detected.