Distributing entanglement over long distances using optical networks is an intriguing macroscopic quantum phenomenon with applications in quantum systems for advanced computing and secure communication1,2. Building quantum networks requires scalable quantum light–matter interfaces1 based on atoms3, ions4 or other optically addressable qubits. Solid-state emitters5, such as quantum dots and defects in diamond or silicon carbide6,7,8,9,10, have emerged as promising candidates for such interfaces. So far, it has not been possible to scale up these systems, motivating the development of alternative platforms. A central challenge is identifying emitters that exhibit coherent optical and spin transitions while coupled to photonic cavities that enhance the light–matter interaction and channel emission into optical fibres. Rare-earth ions in crystals are known to have highly coherent 4f–4f optical and spin transitions suited to quantum storage and transduction11,12,13,14,15, but only recently have single rare-earth ions been isolated16,17 and coupled to nanocavities18,19. The crucial next steps towards using single rare-earth ions for quantum networks are realizing long spin coherence and single-shot readout in photonic resonators. Here we demonstrate spin initialization, coherent optical and spin manipulation, and high-fidelity single-shot optical readout of the hyperfine spin state of single 171Yb3+ ions coupled to a nanophotonic cavity fabricated in an yttrium orthovanadate host crystal. These ions have optical and spin transitions that are first-order insensitive to magnetic field fluctuations, enabling optical linewidths of less than one megahertz and spin coherence times exceeding thirty milliseconds for cavity-coupled ions, even at temperatures greater than one kelvin. The cavity-enhanced optical emission rate facilitates efficient spin initialization and single-shot readout with conditional fidelity greater than 95 per cent. These results showcase a solid-state platform based on single coherent rare-earth ions for the future quantum internet.