
Some hospitals halted routine work, some shops shut their doors and the two countries' governments convened emergency cabinet meetings as officials tried to find out what caused the mass blackout from around 1033 GMT. Outages on such a scale are extremely rare in Europe.
"We do not yet have conclusive information on the reasons for this (power) cut, so I ask the people, as we have done in past crises, to inform themselves through official channels," Spanish Prime Minister Pedro Sanchez said in a national address.
"For the time being, there's no evidence of any civil protection problems. I repeat, there are no problems of insecurity."
He said Spain's national security council would meet again on Monday evening to take stock of the situation.
Reuters witnesses said power had started returning to the Basque country and Barcelona areas of Spain in the early afternoon. It was not clear when power might be restored more widely.
Hospitals in Madrid and Cataluna in Spain suspended all routine medical work but were still attending to critical patients, using backup generators.
Several Spanish oil refineries were shut down and some retail businesses closed in both countries, including grocery chain Lidl and furniture giant IKEA.
"I don't understand anything. I just don't know who to turn to. My daughter in Barcelona is giving birth. We're going to miss the connection to get there," said Angeles Alvarez, a traveller stranded outside Madrid's Atocha railway station.
Images from a Madrid supermarket showed long queues at tills and empty shelves as people rushed to stock up on staples.
The Bank of Spain said electronic banking was functioning "adequately" on backup systems, though residents also reported ATM screens had gone blank.
"I'm in a data centre, and everything has gone off. All the alarms popped up, and now we're with the groups, waiting to find out what happened," said Barcelona resident and engineer Jose Maria Espejo, 40.
In a video posted on X, Madrid Mayor Jose Luis Martinez-Almeida urged city residents to minimise their journeys and stay where they were, adding: "It is essential that the emergency services can circulate."
In Portugal, water supplier EPAL said water supplies could also be disrupted, and queues formed at stores by people seeking to purchase emergency supplies like gaslights, generators and batteries.
The main Portuguese electricity utility, EDP, said it had told customers it had no forecast for when the energy supply would be "normalised", Publico newspaper said. It warned it could take several hours.
Parts of France also suffered a brief outage. RTE, the French grid operator, said it had moved to supplement power to some parts of northern Spain after the outage hit.
GRIDLOCK
Spanish radio stations said part of the Madrid underground was being evacuated, and play at the Madrid Open tennis tournament was suspended.
There were traffic jams in Madrid city centre as traffic lights stopped working, with people in reflective vests standing at intersections to direct traffic.
Hundreds of people stood outside office buildings on Madrid’s streets and there was a heavy police presence around key buildings, directing traffic as well as driving along central atriums with lights, according to a Reuters witness.
One of four tower buildings in Madrid that houses the British Embassy had been evacuated, the witness added.
Local radio reported people trapped in stalled metro cars and elevators.
About 43% of Spain's energy comes from wind and solar power, with nuclear accounting for a further 20% and fossil fuels 23%, according to energy think tank Ember.
Portuguese police said traffic lights were affected across the country, the metro was closed in Lisbon and Porto, and trains were not running.
Lisbon's subway transport operator Metropolitano de Lisboa said the subway was at a standstill with people still inside the trains, according to Publico newspaper.
A source at Portugal's TAP Air said Lisbon airport was running on back-up generators, while AENA, which manages 46 airports in Spain, reported flight delays around the country.
Such widespread outages are unusual in Europe. In 2003 a problem with a hydroelectric power line between Italy and Switzerland caused a major outage across the whole Italian peninsula for around 12 hours.
In 2006 an overloaded power network in Germany caused electricity cuts across parts of the country and in France, Italy, Spain, Austria, Belgium, Netherlands and as far as Morocco.