Context. Models of pure gas-phase chemistry in well-shielded regions of molecular clouds predict relatively high levels of molecular oxygen, O 2 , and water, H 2 O. These high abundances imply high cooling rates, leading to relatively short timescales for the evolution of gravitationally unstable dense cores, forming stars and planets. Contrary to expectations, the dedicated space missions SWAS and Odin typically found only very small amounts of water vapour and essentially no O 2 in the dense star-forming interstellar medium. Aims. Only toward ρ Oph A did Odin detect a very weak line of O 2 at 119 GHz in a beam of size 10 arcmin. The line emission of related molecules changes on angular scales of the order of some tens of arcseconds, requiring a larger telescope aperture such as that of the Herschel Space Observatory to resolve the O 2 emission and pinpoint its origin. Methods. We use the Heterodyne Instrument for the Far Infrared (HIFI) aboard Herschel to obtain high resolution O 2 spectra toward selected positions in the ρ Oph A core. These data are analysed using standard techniques for O 2 excitation and compared to recent PDR-like chemical cloud models.Results. The N J = 3 3 −1 2 line at 487.2 GHz is clearly detected toward all three observed positions in the ρ Oph A core. In addition, an oversampled map of the 5 4 −3 4 transition at 773.8 GHz reveals the detection of the line in only half of the observed area. On the basis of their ratios, the temperature of the O 2 emitting gas appears to vary quite substantially, with warm gas ( > ∼ 50 K) being adjacent to a much colder region, of temperatures lower than 30 K. Conclusions. The exploited models predict that the O 2 column densities are sensitive to the prevailing dust temperatures, but rather insensitive to the temperatures of the gas. In agreement with these models, the observationally determined O 2 column densities do not seem to depend strongly on the derived gas temperatures, but fall into the range N(O 2 ) = 3 to > ∼ 6 × 10 15 cm −2 . Beam-averaged O 2 abundances are about 5 × 10 −8 relative to H 2 . Combining the HIFI data with earlier Odin observations yields a source size at 119 GHz in the range of 4 to 5 arcmin, encompassing the entire ρ Oph A core. We speculate that one of the reasons for the generally very low detection rate of O 2 is the short period of time during which O 2 molecules are reasonably abundant in molecular clouds.