The origin of the supermassive black holes that inhabit the centres of massive galaxies remains unclear1,2. Direct-collapse black holes-remnants of supermassive stars, with masses around 10,000 times that of the Sun-are ideal seed candidates3-6. However, their very existence and their formation environment in the early Universe are still under debate, and their supposed rarity makes modelling their formation difficult7,8. Models have shown that rapid collapse of pre-galactic gas (with a mass infall rate above some critical value) in metal-free haloes is a requirement for the formation of a protostellar core that will then form a supermassive star9,10. Here we report a radiation hydrodynamics simulation of early galaxy formation11,12 that produces metal-free haloes massive enough and with sufficiently high mass infall rates to form supermassive stars. We find that pre-galactic haloes and their associated gas clouds that are exposed to a Lyman-Werner intensity roughly three times the intensity of the background radiation and that undergo at least one period of rapid mass growth early in their evolution are ideal environments for the formation of supermassive stars. The rapid growth induces substantial dynamical heating13,14, amplifying the Lyman-Werner suppression that originates from a group of young galaxies 20 kiloparsecs away. Our results strongly indicate that the dynamics of structure formation, rather than a critical Lyman-Werner flux, is the main driver of the formation of massive black holes in the early Universe. We find that the seeds of massive black holes may be much more common than previously considered in overdense regions of the early Universe, with a co-moving number density up to 10-3 per cubic megaparsec.