M-dwarf stars--hydrogen-burning stars that are smaller than 60 per cent of the size of the Sun--are the most common class of star in our Galaxy and outnumber Sun-like stars by a ratio of 12:1. Recent results have shown that M dwarfs host Earth-sized planets in great numbers: the average number of M-dwarf planets that are between 0.5 to 1.5 times the size of Earth is at least 1.4 per star. The nearest such planets known to transit their star are 39 parsecs away, too distant for detailed follow-up observations to measure the planetary masses or to study their atmospheres. Here we report observations of GJ 1132b, a planet with a size of 1.2 Earth radii that is transiting a small star 12 parsecs away. Our Doppler mass measurement of GJ 1132b yields a density consistent with an Earth-like bulk composition, similar to the compositions of the six known exoplanets with masses less than six times that of the Earth and precisely measured densities. Receiving 19 times more stellar radiation than the Earth, the planet is too hot to be habitable but is cool enough to support a substantial atmosphere, one that has probably been considerably depleted of hydrogen. Because the host star is nearby and only 21 per cent the radius of the Sun, existing and upcoming telescopes will be able to observe the composition and dynamics of the planetary atmosphere.