Using a representative sample of 65 intermediate-mass galaxies at z∼ 0.6, we have investigated the interplay between the main ingredients of chemical evolution: metal abundance, gas mass, stellar mass and star formation rate (SFR). All quantities have been estimated using deep spectroscopy and photometry from ultraviolet to infrared and assuming an inversion of the Kennicutt–Schmitt law for the gas fraction. Six billion years ago, galaxies had a mean gas fraction of 32 ± 3 per cent, i.e. twice that of their local counterparts. Using higher redshift samples from the literature, we explore the gas phases and estimate the evolution of the mean gas fraction of distant galaxies over the last 11 Gyr. The gas fraction increases linearly at the rate of 4 per cent Gyr−1 from z∼ 0 to ∼2.2. We also demonstrate for a statistically representative sample that <4 per cent of the z∼ 0.6 galaxies are undergoing outflow events, in sharp contrast with z∼ 2.2 galaxies. The observed co-evolution of metals and gas over the past 6 Gyr favours a scenario in which the population of intermediate-mass galaxies evolved as closed systems, converting their own gas reservoirs into stars.