Now that γ-ray bursts (GRBs) have been determined to lie at cosmological distances, their isotropic burst energies are estimated to be as high as 1054erg (ref. 2), making them the most energetic phenomena in the Universe. The nature of the progenitors responsible for the bursts remains, however, elusive. The favoured models range from the merger of two neutron stars in a binary system to the collapse of a massive star. Spectroscopic studies of the afterglow emission could reveal details of the environment of the burst, by indicating the elements present, the speed of the outflow and an estimate of the temperature. Here we report an X-ray spectrum of the afterglow of GRB011211, which shows emission lines of magnesium, silicon, sulphur, argon, calcium and possibly nickel, arising in metal-enriched material with an outflow velocity of the order of one-tenth the speed of light. These observations strongly favour models where a supernova explosion from a massive stellar progenitor precedes the burst event and is responsible for the outflowing matter.