Context. Precise stellar masses and radii provide unique information on stellar evolution. In a Galactic context, they may also provide information on the evolution of the Solar neighbourhood. Aims. We aim to determine absolute dimensions for the mid B-type eclipsing binary U Ophiuchi and compare the inferred ages and chemical compositions to those of other binary stars with masses near 5 M . Methods. We determine masses, radii, log g, log T eff , and luminosities for the stars in U Oph from new radial velocities and uvby light curves. By improving the Wilson-Devinney code, we also derive precise apsidal-motion and light-time orbits of this triple system, using 353 times of minimum over 120 years. Finally, we compare the data for U Oph and three similar systems with the predictions of stellar models. Results. The stars in U Oph have masses of 5.27 ± 0.09 M and 4.74 ± 0.07 M , radii of 3.48 ± 0.02 R and 3.11 ± 0.03 R ; we argue that systematic errors are negligible. The apsidal motion period is exceptionally short, U ∼ 21 yr, while the light-time orbit has P 3 ∼ 38.4 yr. The precise log g values for DI Her, U Oph, V760 Sco, and MU Cas, all within 10% of 5 M , place them successively from the ZAMS to the TAMS, at ages of 5−100 × 10 6 yr. Current stellar evolution models fit both stars in each system very well if the (otherwise unconstrained) metal abundance Z is adjusted in each case. Conclusions. More accurate data and/or binary systems with larger mass ratios are needed to actually test stellar models near 5 M . The different Z values found for these young, nearby systems suggest that disk stars form with a range of metal abundances even today, but more data are needed to confirm this result.