Spain's Interior Ministry declared a national emergency, deploying 30,000 police across the nation to keep order as governments from the two countries convened emergency cabinet meetings. Outages on such a scale are extremely rare in Europe.
The cause was unclear, with Portugal suggesting the issue originated in Spain and Spain pointing the finger at a break-up in its connection to France.
Portuguese Prime Minister Luis Montenegro said there was "no indication" a cyberattack had caused the blackout, which began on Monday morning.
Nonetheless, rumours circulated of possible sabotage, and Spanish Prime Minister Pedro Sanchez said he had spoken to NATO Secretary General Mark Rutte.
Sanchez said that the nation had suffered a loss of 15GW of electricity generation in five seconds, equivalent to 60 per cent of national demand. Technicians were working to figure out why that sudden drop occurred, he said.
"This is something that has never happened before," he said.
Joao Conceicao, a board member of Portuguese grid operator REN, told reporters the company had not ruled out the possibility of a "very large oscillation in electrical voltage, first in the Spanish system, which then spread to the Portuguese system".
"There could be a thousand and one causes, it's premature to assess the cause," he said, adding that REN was in contact with Spain.
Spain's grid operator REE blamed a connection failure with France for triggering a knock-on effect.
"The extent of the loss of power was beyond what European systems are designed to handle and caused a disconnection of the Spanish and French grids, which in turn led to the collapse of the Spanish electric system," Eduardo Prieto said.
Earlier, parts of France 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.
In Spain, power started returning to the Basque country and Barcelona areas in the early afternoon, and to parts of capital Madrid on Monday night.
About 61 per cent of electricity had been restored by late Monday, according to the national grid operator.
The blackout had wide-ranging effects across the peninsula.
Hospitals in Madrid and Catalonia 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 retailers closed, including grocery chain Lidl and furniture giant IKEA.
Portuguese police said traffic lights were affected across the country and the metro was closed in Lisbon and Porto, while trains were cancelled in both countries.
Sanchez said on Monday evening that about 35,000 train passengers had been rescued from trains while 11 trains still remained stranded in remote areas.
Images from a Madrid supermarket showed long queues at tills and empty shelves as people rushed to stock up on staples, while 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 appointing themselves to direct vehicles at intersections. Local radio reported people trapped in stalled metro cars and elevators.
with AP and DPA