The presence of young massive stars orbiting on eccentric rings within a few tenths of a parsec of the supermassive black hole in the Galactic centre is challenging for theories of star formation. The high tidal shear from the black hole should tear apart the molecular clouds that form stars elsewhere in the Galaxy, while transporting the stars to the Galactic centre also appears unlikely during their stellar lifetimes. We present numerical simulations of the infall of a giant molecular cloud that interacts with the black hole. The transfer of energy during closest approach allows part of the cloud to become bound to the black hole, forming an eccentric disc that quickly fragments to form stars. Compressional heating due to the black hole raises the temperature of the gas to 100-1000K, ensuring that the fragmentation produces relatively high stellar masses. These stars retain the eccentricity of the disc and, for a sufficiently massive initial cloud, produce an extremely top-heavy distribution of stellar masses. This potentially repetitive process can therefore explain the presence of multiple eccentric rings of young stars in the presence of a supermassive black hole.