solar flare
The second X-class flare of June 10, 2014, appears as a bright flash on the left side of this image.NASA/SDO

Nasa has warned how civilisation was almost sent back 200 years when a huge solar storm came extremely close to hitting Earth.

The space agency said the most powerful coronal mass ejection (CME) to hit the planet for over 150 years missed Earth by just a few days.

Had it hit, it would have caused widespread power blackouts, "disabling everything that plugs into a wall socket".

"Most people wouldn't even be able to flush their toilet because urban water supplies largely rely on electric pumps," Nasa said.

The CME tore through Earth's orbit on 23 July, 2012, but Earth was not there – it had moved out of the storm's path one week earlier.

Daniel Baker, from the University of Colorado, said: "If it had hit, we would still be picking up the pieces. I have come away from our recent studies more convinced than ever that Earth and its inhabitants were incredibly fortunate that the 2012 eruption happened when it did. If the eruption had occurred only one week earlier, Earth would have been in the line of fire."

Northern Lights
Swirls of green and red appear in an aurora over Whitehorse, Yukon on the night of September 3, 2012. The aurora was due to the interaction of a CME from the sun with Earth's magnetosphere. The CME left the sun on August 31 and arrived on September 3.David Cartier, Sr./NASA

Solar storms start with an explosion from the Sun in the magnetic canopy of a sunspot. The most extreme solar storm to hit Earth is known as the Carrington Event, which took place in 1859 and caused intense geomagnetic storms. The Northern Lights could be seen as far south as Cuba, global telegraph lines sparked and some telegraph offices caught on fire – disabling the main form of communication at the time.

A similar storm now would have a "catastrophic effect", with the National Academy of Sciences predicting a total cost of $2trn (£1.1trn). "In my view the July 2012 storm was in all respects at least as strong as the 1859 Carrington Event," Baker said. "The only difference is, it missed."

Researchers have said the chance of Earth being hit by a CME of this strength within the next 10 years is high, and that "we need to be prepared".

The odds of a Carrington-class storm hitting is 12%. Pete Riley, a physicist from Predictive Science Inc, made this finding after analysing records of solar storms for the last 50 years.

"Initially, I was quite surprised that the odds were so high, but the statistics appear to be correct. It is a sobering figure," he said.