In the copper oxide parent compounds of the high-transition-temperature superconductors the valence electrons are localized--one per copper site--by strong intra-atomic Coulomb repulsion. A symptom of this localization is antiferromagnetism, where the spins of localized electrons alternate between up and down. Superconductivity appears when mobile 'holes' are doped into this insulating state, and it coexists with antiferromagnetic fluctuations. In one approach to describing the coexistence, the holes are believed to self-organize into 'stripes' that alternate with antiferromagnetic (insulating) regions within copper oxide planes, which would necessitate an unconventional mechanism of superconductivity. There is an apparent problem with this picture, however: measurements of magnetic excitations in superconducting YBa2Cu3O6+x near optimum doping are incompatible with the naive expectations for a material with stripes. Here we report neutron scattering measurements on stripe-ordered La1.875Ba0.125CuO4. We show that the measured excitations are, surprisingly, quite similar to those in YBa2Cu3O6+x (refs 9, 10) (that is, the predicted spectrum of magnetic excitations is wrong). We find instead that the observed spectrum can be understood within a stripe model by taking account of quantum excitations. Our results support the concept that stripe correlations are essential to high-transition-temperature superconductivity.