Soft-γ-ray repeaters (SGRs) are galactic X-ray stars that emit numerous short-duration (about 0.1s) bursts of hard X-rays during sporadic active periods. They are thought to be magnetars: strongly magnetized neutron stars with emissions powered by the dissipation of magnetic energy. Here we report the detection of a long (380s) giant flare from SGR 1806-20, which was much more luminous than any previous transient event observed in our Galaxy. (In the first 0.2s, the flare released as much energy as the Sun radiates in a quarter of a million years.) Its power can be explained by a catastrophic instability involving global crust failure and magnetic reconnection on a magnetar, with possible large-scale untwisting of magnetic field lines outside the star. From a great distance this event would appear to be a short-duration, hard-spectrum cosmic γ-ray burst. At least a significant fraction of the mysterious short-duration γ-ray bursts may therefore come from extragalactic magnetars.