Every once and a while a huge gamma ray burst from space strikes a planet. If the planet is like Earth and the gamma ray burst is severe enough, this kills the ozone layer from the outside and everything dies, because the biosphere on the planet is no longer protected from cosmic rays.
Fortunately, about 65% of gamma ray bursts are survivable for planets like Earth. Also, they aren't terribly likely to hit planets way out on the fringe of a galaxy, like ours, as opposed to planets in the inner galaxies where the higher density of stars and a complicated confluence of other considerations related to the age and metal composition of the stars involved make gamma ray bursts more common.
So, bottom line:
The bad news is that I have just informed you of a new existential threat to all life on Earth that you'd probably never considered or worried about until now. But, the good news is that this particular threat is probably less likely to kill us all than all sorts of other potential threats from space like large heavy objects crashing into the planet, or the Sun expanding and frying the planet, or space aliens invading us. So, really, it's no big thing.
A planet having protective ozone within the collimated beam of a Gamma Ray Burst (GRB) may suffer ozone depletion, potentially causing a mass extinction event to existing life on a planet's surface and oceans. We model the dangers of long GRBs to planets in the Milky Way and utilize a static statistical model of the Galaxy that matches major observable properties, such as the inside-out star formation history, metallicity evolution, and 3-dimensional stellar number density distribution. The GRB formation rate is a function of both the star formation history and metallicity; however, the extent to which chemical evolution reduces the GRB rate over time in the Milky Way is still an open question. Therefore, we compare the damaging effects of GRBs to biospheres in the Milky Way using two models. One model generates GRBs as a function of the inside-out star formation history. The other model follows the star formation history, but generates GRB progenitors as a function of metallicity, thereby favoring metal-poor host regions of the Galaxy over time. If the GRB rate only follows the star formation history, the majority of the GRBs occur in the inner Galaxy. However, if GRB progenitors are constrained to low metallicity environments, then GRBs only form in the metal-poor outskirts at recent epochs. Interestingly, over the past 1 Gyr, the surface density of stars (and their corresponding planets) that survive a GRB is still greatest in the inner galaxy in both models. The present day danger of long GRBs to life at the solar radius (R⊙=8 kpc) is low. We find that at least ∼65% of stars survive a GRB over the past 1 Gyr. Furthermore, when the GRB rate was expected to have been enhanced at higher redshifts, such as z≳0.5, our results suggest that a large fraction of planets would have survived these lethal GRB events.
Michael G. Gowanlock, "Astrobiological Effects of Gamma-Ray Bursts in the Milky Way Galaxy" (29 September 2016)