Earth was blasted by a high-energy burst of radiation from space in the eighth century, scientists believe.
Luckily for the human race, the source of the gamma ray burst (GRB) was at least 3,000 light years away.
At closer range the radiation could have stripped away the Earth's ozone layer, leading to the extinction of terrestrial life.
Gamma ray bursts are the most powerful explosions known in the universe. Each one corresponds to around a thousand Earths being vaporised into pure energy in seconds.
Most occur billions of light years away, and until the last decade their origin remained a cosmological mystery.
The GRB that struck the Earth towards the end of the eighth century may have been triggered by the cataclysmic collision of two black holes or neutron stars.
Both are dead star remnants. A neutron star is the super-dense core of a burned out star, and a black hole is a region of space where matter has collapsed to the point where even light is trapped by gravity.
Scientists found a chemical signature of the GRB in tree rings and Antarctic ice cores dating back to the year 775.
High levels of particular isotopes, or atomic strains, of carbon and beryllium were detected that form when high-intensity radiation bombards nitrogen in the atmosphere.
A solar flare would not have produced a strong enough blast of radiation to account for the excess levels of one isotope, carbon-14, found in Japanese cedar trees.
Large flares would also have produced dramatic displays of the northern and southern lights, but there is no evidence of such phenomena in historical records.
Nor is there any record of another possible source of the radiation - a nearby supernova, or exploding star. This would have created a bright light in the sky that at the time would almost certainly have been seen as an omen or religious sign.
Dr Ralph Neuhauser, from the University of Jena in Germany, whose theory about the GRB is reported in the journal Monthly Notices of the Royal Astronomical Society, said: "If the gamma ray burst had been much closer to the Earth it would have caused significant harm to the biosphere. But even thousands of light years away, a similar event today could cause havoc with the sensitive electronic systems that advanced societies have come to depend on.
"The challenge now is to establish how rare such carbon-14 spikes are - ie, how often such radiation bursts hit the Earth."
The evidence suggests that the gamma ray burst occurred somewhere in our galaxy, the Milky Way, between 3,000 and 12,000 light years from the Sun.
A relatively nearby GRB would have emitted some visible light that could have been seen for a few days.
It may have easily been missed, but the scientists suggest looking through historical texts in case any reference to the short-lived event can be found.