© 2015 The Authors Published by Oxford University Press on behalf of the Royal Astronomical Society. We investigate the abundance of galactic molecular hydrogen (H2) in the 'Evolution and Assembly of GaLaxies and their Environments' (EAGLE) cosmological hydrodynamic simulations. We assign H2 masses to gas particles in the simulations in post-processing using two different prescriptions that depend on the local dust-to-gas ratio and the interstellar radiation field. Both result in H2 galaxy mass functions that agree well with observations in the local and high-redshift Universe. The simulations reproduce the observed scaling relations between the mass of H2 and the stellar mass, star formation rate and stellar surface density. Towards high redshifts, galaxies in the simulations display larger H2 mass fractions and lower H2 depletion time-scales, also in good agreement with observations. The comoving mass density of H2 in units of the critical density, ΩH2, peaks at z ~ 1.2-1.5, later than the predicted peak of the cosmic star formation rate activity, at z ~ 2. This difference stems from the decrease in gas metallicity and increase in interstellar radiation field with redshift, both of which hamper H2 formation. We find that the cosmic H2 budget is dominated by galaxies with MH2 > 109M·, star formation rates -1 and stellar masses Mstellar > 1010M·, which are readily observable in the optical and near-IR. The match between the H2 properties of galaxies that emerge in the simulations and observations is remarkable, particularly since H2 observations were not used to adjust parameters in EAGLE.