Magnetars are neutron stars with X-ray and soft γ-ray outbursts thought to be powered by intense internal magnetic fields. Like conventional neutron stars in the form of radio pulsars, magnetars exhibit `glitches' during which angular momentum is believed to be transferred between the solid outer crust and the superfluid component of the inner crust. The several hundred observed glitches in radio pulsars and magnetars have involved a sudden spin-up (increase in the angular velocity) of the star, presumably because the interior superfluid was rotating faster than the crust. Here we report X-ray timing observations of the magnetar 1E 2259+586 (ref. 8), which exhibited a clear `anti-glitch'--a sudden spin-down. We show that this event, like some previous magnetar spin-up glitches, was accompanied by multiple X-ray radiative changes and a significant spin-down rate change. Such behaviour is not predicted by models of neutron star spin-down and, if of internal origin, is suggestive of differential rotation in the magnetar, supporting the need for a rethinking of glitch theory for all neutron stars.