Magnetic resonance imaging (MRI) has revolutionized biomedical science by providing non-invasive, three-dimensional biological imaging. However, spatial resolution in conventional MRI systems is limited to tens of micrometres, which is insufficient for imaging on molecular scales. Here, we demonstrate an MRI technique that provides subnanometre spatial resolution in three dimensions, with single electron-spin sensitivity. Our imaging method works under ambient conditions and can measure ubiquitous 'dark' spins, which constitute nearly all spin targets of interest. In this technique, the magnetic quantum-projection noise of dark spins is measured using a single nitrogen-vacancy (NV) magnetometer located near the surface of a diamond chip. The distribution of spins surrounding the NV magnetometer is imaged with a scanning magnetic-field gradient. To evaluate the performance of the NV-MRI technique, we image the three-dimensional landscape of electronic spins at the diamond surface and achieve an unprecedented combination of resolution (0.8 nm laterally and 1.5 nm vertically) and single-spin sensitivity. Our measurements uncover electronic spins on the diamond surface that can potentially be used as resources for improved magnetic imaging. This NV-MRI technique is immediately applicable to diverse systems including imaging spin chains, readout of spin-based quantum bits, and determining the location of spin labels in biological systems.