We incorporate a simple scheme for the growth of supermassive black holes into semi-analytic models that follow the formation and evolution of galaxies in a cold dark matter-dominated Universe. We assume that supermassive black holes are formed and fuelled during major mergers. If two galaxies of comparable mass merge, their central black holes coalesce and a few per cent of the gas in the merger remnant is accreted by the new black hole over a time-scale of a few times 107 yr. With these simple assumptions, our model not only fits many aspects of the observed evolution of galaxies, but also reproduces quantitatively the observed relation between bulge luminosity and black hole mass in nearby galaxies, the strong evolution of the quasar population with redshift, and the relation between the luminosities of nearby quasars and those of their host galaxies. The strong decline in the number density of quasars from z∼2 to z=0 is a result of the combination of three effects: (i) a decrease in the merging rate; (ii) a decrease in the amount of cold gas available to fuel black holes, and (iii) an increase in the time-scale for gas accretion. The predicted decline in the total content of cold gas in galaxies is consistent with that inferred from observations of damped Lyα systems. Our results strongly suggest that the evolution of supermassive black holes, quasars and starburst galaxies is inextricably linked to the hierarchical build-up of galaxies.