We present the detection of molecular oxygen with Odin toward the dense molecular core rho Oph A, which is part of a region of active star formation. The observed spectral line is the (N,J = 1,1-1,0) ground state transition of molecular oxygen at 119 GHz (2.5 mm wavelength). The center of the line is at the LSR velocity of a number of optically thin lines from other species in the region and the O2 line also has a very similar, narrow, line width. Within the 10 arcmin beam, the integrated line intensity is 28 mK km/s, which corresponds to 5 sigma of the rms noise. A standard LTE analysis results in an O2 abundance of 5E(-8), with an uncertainty of at least a factor of two. We show that standard methods, however, do not apply in this case, as the coupling of the Odin beam to the source structure needs to be accounted for. Preliminary model results indicate O2 abundances to be higher by one order of magnitude than suggested by the standard case. This model predicts the 487 GHz line of O2 to be easily detectable by the future Herschel-HIFI facility, but to be out of reach for observations on a shorter time scale with the Odin space observatory.