Galaxies and quasars are thought to provide the bulk of the photons responsible for ionizing the hydrogen in the intergalactic medium (IGM). We use a large set of hydrodynamical simulations, combined with measurements of the Lyα opacity of the IGM taken from the literature, to obtain robust estimates of the photoionization rate per hydrogen atom at z= 5 and 6. We find the photoionization rate drops by a factor of 2 and 4, respectively, compared to our recent measurements at z= 2–4. The number of ionizing photons emitted by known sources at z= 5 and 6, based on an extrapolation of source numbers below the detection limit and standard assumptions for the relationship between the ionizing emissivity and observed luminosity density at 1500 Å, are in reasonable agreement with the photoionization rates inferred from the Lyα forest if the escape fraction of ionizing photons from galaxies is large (≳20 per cent). The expected number of ionizing photons from observed sources at these redshifts therefore appears sufficient to maintain the IGM in its highly ionized state. Claims to the contrary may be attributed to the adoption of an unduly high value for the clumping factor of ionized hydrogen. Using physically motivated assumptions for the mean free path of ionizing photons our measurements of the photoionization rate can be turned into an estimate of the ionizing emissivity. In comoving units the inferred ionizing emissivity is nearly constant over the redshift range 2–6 and corresponds to 1.5–3 photons emitted per hydrogen atom over a time interval corresponding to the age of the Universe at z= 6. This strongly suggests that the epoch of reionization was photon-starved and extended. Completion of reionization at or before z= 6 requires either an emissivity which rises towards higher redshifts or one which remains constant but is dominated by sources with a rather hard spectral index. For standard assumptions, the ionizing emissivity required for completion of reionization at or before z= 6 lies at the upper end of recently reported values from searches for high-redshift galaxies at z= 8–10.