Nuclear magnetic resonance (NMR) spectroscopy and magnetic resonance imaging (MRI) provide non-invasive information about multiple nuclear species in bulk matter, with wide-ranging applications from basic physics and chemistry to biomedical imaging. However, the spatial resolution of conventional NMR and MRI is limited to several micrometres even at large magnetic fields (>1 T), which is inadequate for many frontier scientific applications such as single-molecule NMR spectroscopy and in vivo MRI of individual biological cells. A promising approach for nanoscale NMR and MRI exploits optical measurements of nitrogen–vacancy (NV) colour centres in diamond, which provide a combination of magnetic field sensitivity and nanoscale spatial resolution unmatched by any existing technology, while operating under ambient conditions in a robust, solid-state system. Recently, single, shallow NV centres were used to demonstrate NMR of nanoscale ensembles of proton spins, consisting of a statistical polarization equivalent to ∼100–1,000 spins in uniform samples covering the surface of a bulk diamond chip. Here, we realize nanoscale NMR spectroscopy and MRI of multiple nuclear species (1H, 19F, 31P) in non-uniform (spatially structured) samples under ambient conditions and at moderate magnetic fields (∼20 mT) using two complementary sensor modalities.