The standard cosmological model, now strongly constrained by direct observations of the Universe at early epochs, is very successful in describing the evolution of structure on large and intermediate scales1. Unfortunately, serious contradictions remain on smaller, galactic scales1,2. Among the main small-scale problems is a significant and persistent discrepancy between observations of nearby galaxies, which imply that galactic dark matter haloes have a density profile with a flat core3-6, and the cosmological model, which predicts that the haloes should have divergent density (a cusp) at the centre7,8. Here we report numerical simulations that show that random bulk motions of gas in small primordial galaxies, of the magnitude expected in these systems, will result in a flattening of the central dark matter cusp on relatively short timescales (∼108years). Gas bulk motions in early galaxies are driven by supernova explosions that result from ongoing star formation. Our mechanism is general, and would have operated in all star-forming galaxies at redshiftsz ≥ 10. Once removed, the cusp cannot be reintroduced during the subsequent mergers involved in the build-up of larger galaxies9,10. As a consequence, in the present Universe both small and large galaxies would have flat dark matter core density profiles, in agreement with observations.