We explore the mass-assembly and chemical enrichment histories of star forming galaxies by applying a population synthesis method to a sample of 84828 galaxies from the Sloan Digital Sky Survey Data Release 5. Our method decomposes the entire observed spectrum in terms of a sum of simple stellar populations spanning a wide range of ages and metallicities, thus allowing the reconstruction of galaxy histories. A comparative study of galaxy evolution is presented, where galaxies are grouped onto bins of nebular abundances or mass. We find that galaxies whose warm interstellar medium is poor in heavy elements are slow in forming stars. Their stellar metallicities also rise slowly with time, reaching their current values ($Z_star sim 1/3 Z_odot$) in the last $sim 100$ Myr of evolution. Systems with metal rich nebulae, on the other hand, assembled most of their mass and completed their chemical evolution long ago, reaching $Z_star sim Z_odot$ already at lookback times of several Gyr. These same trends, which are ultimately a consequence of galaxy downsizing, appear when galaxies are grouped according to their stellar mass. The reconstruction of galaxy histories to this level of detail out of integrated spectra offers promising prospects in the field of galaxy evolution theories.