Anomalous X-ray pulsars (AXPs) are a class of rare X-ray emitting pulsars whose energy source has been perplexing for some 20 years. Unlike other X-ray emitting pulsars, AXPs cannot be powered by rotational energy or by accretion of matter from a binary companion star, hence the designation 'anomalous'. Many of the rotational and radiative properties of the AXPs are strikingly similar to those of another class of exotic objects, the soft-gamma-ray repeaters (SGRs). But the defining property of the SGRs--their low-energy-gamma-ray and X-ray bursts--has not hitherto been observed for AXPs. Soft-gamma-ray repeaters are thought to be 'magnetars', which are young neutron stars whose emission is powered by the decay of an ultra-high magnetic field; the suggestion that AXPs might also be magnetars has been controversial. Here we report two X-ray bursts, with properties similar to those of SGRs, from the direction of the anomalous X-ray pulsar 1E1048.1 - 5937. These events imply a close relationship (perhaps evolutionary) between AXPs and SGRs, with both being magnetars.