For almost two decades the properties of `dwarf' galaxies have challenged the cold dark matter (CDM) model of galaxy formation. Most observed dwarf galaxies consist of a rotating stellar disk embedded in a massive dark-matter halo with a near-constant-density core. Models based on the dominance of CDM, however, invariably form galaxies with dense spheroidal stellar bulges and steep central dark-matter profiles, because low-angular-momentum baryons and dark matter sink to the centres of galaxies through accretion and repeated mergers. Processes that decrease the central density of CDM halos have been identified, but have not yet reconciled theory with observations of present-day dwarfs. This failure is potentially catastrophic for the CDM model, possibly requiring a different dark-matter particle candidate. Here we report hydrodynamical simulations (in a framework assuming the presence of CDM and a cosmological constant) in which the inhomogeneous interstellar medium is resolved. Strong outflows from supernovae remove low-angular-momentum gas, which inhibits the formation of bulges and decreases the dark-matter density to less than half of what it would otherwise be within the central kiloparsec. The analogues of dwarf galaxies-bulgeless and with shallow central dark-matter profiles-arise naturally in these simulations.