  Soft X-ray absorption in excess of Galactic is observed in the afterglows of
most gamma-ray bursts (GRBs), but the correct solution to its origin has not
been arrived at after more than a decade of work, preventing its use as a
powerful diagnostic tool. We resolve this long-standing problem and find that
He in the GRB's host HII region is responsible for most of the absorption. We
show that the X-ray absorbing column density (N_Hx) is correlated with both the
neutral gas column density and with the optical afterglow extinction (Av). This
correlation explains the connection between dark bursts and bursts with high
N_Hx values. From these correlations we exclude an origin of the X-ray
absorption which is not related to the host galaxy, i.e. the intergalactic
medium or intervening absorbers are not responsible. We find that the
correlation with the dust column has a strong redshift evolution, whereas the
correlation with the neutral gas does not. From this we conclude that the
column density of the X-ray absorption is correlated with the total gas column
density in the host galaxy rather than the metal column density, in spite of
the fact that X-ray absorption is typically dominated by metals. The strong
redshift evolution of N_Hx/Av is thus a reflection of the cosmic metallicity
evolution of star-forming galaxies. We conclude that the absorption of X-rays
in GRB afterglows is caused by He in the HII region hosting the GRB. While dust
is destroyed and metals are stripped of all of their electrons by the GRB to
great distances, the abundance of He saturates the He-ionising UV continuum
much closer to the GRB, allowing it to remain in the neutral or singly-ionised
state. Helium X-ray absorption explains the correlation with total gas, the
lack of strong evolution with redshift as well as the absence of dust, metal or
hydrogen absorption features in the optical-UV spectra.
