X-ray flares detected in nearly half of gamma-ray-burst (GRB) afterglows are one of the most intriguing phenomena in highenergy astrophysics 1-8 . All of the observations indicate that the central engines of bursts, after the gamma-ray emission has ended, still have long periods of activity, during which energetic explosions eject relativistic materials, leading to late-time X-ray emission 2,9,10 . It is thus expected that X-ray flares provide important clues as to the nature of the central engines of GRBs, and more importantly, unveil the physical mechanism of the flares themselves, which has so far remained mysterious. Here we report statistical results of X-ray flares of GRBs with known redshifts, and show that X-ray flares and solar flares share three statistical properties: power-law frequency distributions for energies, durations and waiting times. All of the distributions can be well understood within the physical framework of a self-organized criticality (SOC) system. The statistical properties of X-ray flares of GRBs are similar to solar flares, and thus both can be attributed to a SOC process. Both types of flares may be driven by a magnetic reconnection process, but X-ray flares of GRBs are produced in ultra-strongly magnetized millisecond pulsars 11,12 or long-term hyperaccreting disks around stellar-mass black holes 13 .GRBs are flashes of gamma-rays occurring at cosmological distances with an isotropic-equivalent energy release from 10 51 to 10 54 ergs 9,10,14,15 . They can be sorted into two classes: shortduration hard-spectrum bursts (< 2 s) and long-duration softspectrum bursts 16 . Thanks to the rapid-response capability and high sensitivity of the Swift satellite 17 , numerous unforeseen features have been discovered, one of which is that about half of the bursts have large, late-time X-ray flares with short rise and decay times 4,5 . Unexpected X-ray flares with an isotropicequivalent energy from 10 48 to 10 52 ergs have been detected for both long and short bursts 4,6,7 . The occurrence times of X-ray flares range from a few seconds to 10 6 seconds after the GRB trigger 8 . Until now, the physical mechanism of X-ray flares has remained mysterious, although some models have been proposed 9,10 . Due to the 8-year observations of Swift, plentiful X-ray flare data have been collected. Here we investigate the frequency distributions of energies, durations and waiting times of GRB X-ray flares for the first time. On the other hand, it is well known that solar flares with a timescale of hours are explosive phenomena in the solar atmosphere with an energy release of about 10 28 -10 32 ergs, which are widely believed to be triggered by a magnetic reconnection process 18 . They have been observed in broadband electromagnetic waves, but we focus here on solar hard X-ray flares.Although X-ray flares are common phenomena in GRBs and the Sun, the flare energy spans about 20 orders of magnitude and an outstanding question appears, namely, do GRB X-ray flares and solar flares have a similar physical mechani...