Spain’s highest criminal court will investigate whether “an act of computer sabotage” was behind an unprecedented blackout that brought most of the country along with neighbouring Portugal to a standstill.
A judge at the Audiencia Nacional said “cyberterrorism was among the possible explanations” for the blackout.
More than 99% of power in Spain had been restored by 6am on Tuesday, according to Spanish power distributor Red Electrica.
The blackout saw thousands of train passengers stranded and left millions of people without phone and internet coverage and access to cash from ATMs across the Iberian Peninsula.
Spanish Prime Minister Pedro Sanchez earlier vowed to have the entire country of 48 million with their lights back on by the end of the day.
Portugal's government has confirmed that power supplies have been restored after Monday's nationwide blackout.
Water supplies are now running across the whole of Portugal, and metro systems in Lisbon and Porto are operating, though some delays remain.
Red Electrica head of operations Eduardo Prieto said the event was "exceptional and extraordinary".
It was the second serious European power outage in less than six weeks after a March 20 fire shut down Heathrow Airport, and it came as authorities across Europe gird against sabotage backed by Russia.
The Portuguese National Cybersecurity Centre in a statement said there was no sign the outage was due to a cyber attack.
European Commission executive vice president in charge of promoting clean energy Teresa Ribera indicated the same to journalists in Brussels and called the power outage "one of the most serious episodes recorded in Europe in recent times".
The Spanish prime minister said that a problem in the European grid caused the huge power outage that struck Spain, Portugal and parts of France.
Mr Sanchez described the problem in the European grid as a "strong oscillation" and added that the cause is still being determined.
The Spanish leader asked the public to refrain from speculation and said no theory about the cause of the outage had been discarded.
"We are analysing all the potential causes without discarding any hypothesis," the prime minister said.
He went on to detail that, at 12.22pm on Monday, Spain's power grid lost 15 gigawatts, the equivalent of 60% of its national demand, in a matter of five seconds.
"We have never had a complete collapse of the system," he added.
Mr Sanchez thanked the governments of France and Morocco where energy was being pulled from to restore power to north and southern Spain.
Subway and railway trains were halted, phone service unavailable and traffic lights and cash machines not working for many of the 50 million people who live across the peninsula.
By mid-afternoon, voltage was progressively being restored in the north, south and west of the peninsula, Red Electrica said.
The company declined to speculate on the causes of the huge blackout.
The outage hit across Spain and Portugal, including their capitals, Madrid and Lisbon. Offices closed and traffic was gridlocked as traffic lights stopped working. It was not possible to make calls on some mobile phone networks, though some apps were working.

In Barcelona, residents walked into stores searching for battery-powered radios and civilians directed traffic at junctions along the Gran Via avenue that cuts through the city.
The countries have a combined population of more than 50 million people. It was not immediately clear how many were affected. It is rare to have such a widespread outage across the Iberian peninsula.
Mr Sanchez convened an extraordinary meeting of Spain's National Security Council and visited Red Electrica to follow efforts at restoring grid operations. The Portuguese cabinet convened an emergency meeting at the prime minister's residence.
Spain's public broadcaster RTVE said a major power outage hit several regions of the country just after midday local time, leaving its newsroom, Spain's parliament in Madrid and subway stations across the country in the dark.
A graph on Spain's electricity network website showing demand across the country indicated a steep drop at around 12.15pm from 27,500MW to near 15,000MW.
Spanish airports were operating on backup electrical systems and some flights were delayed, according to Aena, the company that runs 56 airports in Spain including Madrid and Barcelona.
In Lisbon, terminals closed and throngs of tourists sat outside in the sun and the shade waiting for news about their flights.
"We haven't seen any plane arriving or departing in the 50 minutes we've been waiting here," Dutch tourist Marc Brandsma told The Associated Press.
Train services in both countries ground to a halt. Video aired on Spanish television showed people evacuating metro stations in Madrid and empty stations with trains stopped in Barcelona.
The Spanish Parliament in Madrid closed and play at the Madrid Open tennis tournament was suspended. Three matches were under way when power went down.

Spain's traffic department asked citizens to avoid using their cars as much as possible because of the power outage, which affected traffic lights and electrical road signage.
Barcelona's streets filled with throngs of people milling about in front of darkened shops and offices and exchanging information on what had happened.
Immediate concerns were which phone companies still had some, at least, spotty coverage, or where internet access might be found. Another concern was how to get home with the subway shut and public buses packed. Some took advantage of the lack of connectivity and transport to enjoy the sunshine on restaurant terraces.
In Terrassa, an industrial town 30 miles from Barcelona, stores selling generators were out of stock after people lined up to buy them.
In Portugal, a country of some 10.6 million people, the outage hit Lisbon and surrounding areas, as well as northern and southern parts. Portuguese police placed more officers on duty to direct traffic and cope with increased requests for help, including from people trapped in lifts.
Hospitals and other emergency services in both Spain and Portugal switched to generators. Petrol stations stopped working.
Portugal's National Authority for Emergencies and Civil Protection said backup power systems were operating.
Several Lisbon subway coaches were evacuated, reports said. Also in Portugal, courts stopped work and cash machines and electronic payment systems were affected.