We investigate the metal enrichment of the intracluster medium (ICM) in the framework of hierarchical models of galaxy formation. We calculate the formation and evolution of galaxies and clusters using a semi-analytical model which includes the effects of flows of gas and metals both into and out of galaxies. For the first time in a semi-analytical model, we calculate the production of both alpha and iron-peak elements based on theoretical models for the lifetimes and ejecta of type Ia and type II supernovae (SNe Ia and SNe II). It is essential to include the long lifetimes of the SNIa progenitors in order to correctly model the evolution of the iron-peak elements. We find that if all stars form with an IMF similar to that found in the solar neighbourhood, then the metallicities of O, Mg, Si and Fe in the ICM are predicted to be 2-3 times lower than observed values. In contrast, a model (also favoured on other grounds) in which stars formed in bursts triggered by galaxy mergers have a top-heavy IMF reproduces the observed ICM abundances of O, Mg, Si and Fe. The same model predicts ratios of ICM mass to total stellar luminosity in clusters which agree well with observations. According to our model, the bulk of the metals in clusters are produced by L* and brighter galaxies. [abridged]