Incibe and the Spanish Government are investigating a possible cyberattack as the cause of the blackout.
Both the National Cybersecurity Institute (Incibe) and the Ministry of the Interior are investigating the possibility that the blackout that has left almost all of Spain without power is due to a potential cyberattack. According to ABC, the situation is being investigated, but it has not yet been confirmed that the problem is due to a potential breach in the security of the electrical grid.
This outlet has contacted several cybersecurity experts, and all of them point out that it is too early to draw conclusions.
Be that as it may, it won't be the first time a country loses power due to a cyberattack. In 2015, Ukraine suffered a blackout that left much of the country without power due to a malicious code infection. A year later, another similar incident affected much of the city of Kyiv.

The blackout began around 12:35 a.m. and caused power outages in stores, airports, subway services, and traffic lights. Some parts of Spain outside the Iberian Peninsula, such as Ceuta, Melilla, the Balearic Islands, and the Canary Islands, were not affected.
ABC.es