Graphene, a single-layer network of carbon atoms, has outstanding electrical and mechanical properties1. Graphene ribbons with nanometre-scale widths2,3 (nanoribbons) should exhibit half-metallicity4 and quantum confinement. Magnetic edges in graphene nanoribbons5,6 have been studied extensively from a theoretical standpoint because their coherent manipulation would be a milestone for spintronic7 and quantum computing devices8. However, experimental investigations have been hampered because nanoribbon edges cannot be produced with atomic precision and the graphene terminations that have been proposed are chemically unstable9. Here we address both of these problems, by using molecular graphene nanoribbons functionalized with stable spin-bearing radical groups. We observe the predicted delocalized magnetic edge states and test theoretical models of the spin dynamics and spin–environment interactions. Comparison with a non-graphitized reference material enables us to clearly identify the characteristic behaviour of the radical-functionalized graphene nanoribbons. We quantify the parameters of spin–orbit coupling, define the interaction patterns and determine the spin decoherence channels. Even without any optimization, the spin coherence time is in the range of microseconds at room temperature, and we perform quantum inversion operations between edge and radical spins. Our approach provides a way of testing the theory of magnetism in graphene nanoribbons experimentally. The coherence times that we observe open up encouraging prospects for the use of magnetic nanoribbons in quantum spintronic devices.