Context: Hydrogen peroxide (HOOH) was recently detected toward rho Oph A. Subsequent astrochemical modeling that included reactions in the gas phase and on the surface of dust grains was able to explain the observed abundance, and highlighted the importance of grain chemistry in the formation of HOOH as an intermediate product in water formation. This study also predicted that the hydroperoxyl radical HO2, the precursor of HOOH, should be detectable. Aims: We aim at detecting the hydroperoxyl radical HO2 in rho Oph A. Methods: We used the IRAM 30m and the APEX telescopes to target the brightest HO2 lines at about 130 and 260 GHz. Results: We detect five lines of HO2 (comprising seven individual molecular transitions). The fractional abundance of HO2 is found to be about 1e-10, a value similar to the abundance of HOOH. This observational result is consistent with the prediction of the above mentioned astrochemical model, and thereby validates our current understanding of the water formation on dust grains. Conclusions: This detection, anticipated by a sophisticated gas-grain chemical model, demonstrates that models of grain chemistry have improved tremendously and that grain surface reactions now form a crucial part of the overall astrochemical network.