It remains a challenge to obtain biocompatible afterglow materials with long emission wavelengths, durable lifetimes, and good water solubility. Herein we develop a photooxidation strategy to construct near-infrared afterglow carbon nanodots with an extra-long lifetime of up to 5.9 h, comparable to that of the well-known rare-earth or organic long-persistent luminescent materials. Intriguingly, size-dependent afterglow lifetime evolution from 3.4 to 5.9 h has been observed from the carbon nanodots systems in aqueous solution. With structural/ultrafast dynamics analysis and density functional theory simulations, we reveal that the persistent luminescence in carbon nanodots is activated by a photooxidation-induced dioxetane intermediate, which can slowly release and convert energy into luminous emission via the steric hindrance effect of nanoparticles. With the persistent near-infrared luminescence, tissue penetration depth of 20 mm can be achieved. Thanks to the high signal-to-background ratio, biological safety and cancer-specific targeting ability of carbon nanodots, ultralong-afterglow guided surgery has been successfully performed on mice model to remove tumor tissues accurately, demonstrating potential clinical applications. These results may facilitate the development of long-lasting luminescent materials for precision tumor resection.