  Recent observations suggest that hydrogen reionization ends late ($z \simeq
6$) and proceeds quickly. We present here a new model of the meta-galactic
UV/X-ray background (UVB) that is consistent with this. It adopts the most
recent determinations of the ionizing emissivity due to stars and AGN, as well
as of the HI absorber column density distribution. Another major improvement is
a new treatment of the intergalactic medium (IGM) opacity for ionizing photons
that is able to consistently capture the transition from a neutral to an
ionized IGM. Previous synthesis models of the UVB, when used in simulations,
yield reionization and thermal histories that are inconsistent with the assumed
ionizing emissivities. With our new treatment, this discrepancy is fully
resolved. In our fiducial model, galaxies leaking $\lesssim 18\%$ of their
Lyman continuum emission drive HI reionization, while AGN drive HeII
reionization (completing at $z \simeq 6.2$ and $2.8$ respectively). Due to the
limited time available for cooling between HI and HeII reionization, higher IGM
temperatures are predicted for late reionization scenarios. In our fiducial
model, the predicted temperatures agree well with observational constraints at
$z \lesssim 4$, while being slightly high compared to (somewhat uncertain) data
above that. Models with a larger contribution of AGN are instead disfavoured by
the temperature data, as well as by measurements of the HI and HeII
Lyman-$\alpha$ forest opacities. We also present "equivalent-equilibrium"
ionization/heating rates that mimic our fiducial UVB model for use in
simulation codes that assume ionization equilibrium.
