For Spanish national elections, none thus far though we've come somewhat close in the past I guess, and several polls as of now predict such a scenario. However, for regional elections there have been 4 cases, all because of malapportionment:
Canary Islands, 2015 (60 seats)
PSOE: 19.9% (15)PP: 18.6% (12)CC: 18.2% (18)The minor islands (ie not Gran Canaria/Tenerife) have only 50% of seats even though they account for 82% of the Canarian population. CC is quite strong in the minor islands, winning all but La Gomera (a former socialist stronghold which voted for a PSOE splitter in 2015)
CC keeps their incumbent government coalition with PSOE, with a CC leader but they break it after 1 year and a half. The Canary Islands are notorious for their rotten electoral system that unfairly benefits CC.
https://en.wikipedia.org/wiki/Canarian_regional_election,_2015Catalonia, 2003 (135 seats)
PSC: 31.2% (42)CiU: 30.9% (46)https://en.wikipedia.org/wiki/Catalan_regional_election,_2003Catalonia, 1999 (135 seats)
PSC: 37.9% (50)CiU: 37.7% (56)https://en.wikipedia.org/wiki/Catalan_regional_election,_1999Both a very similar scenario. Barcelona is underrepresented compared to the 3 other Catalan provinces. PSC was really strong in Barcelona, but CiU was stronger in the overrepresented rural and more nationalist provinces. End result is that in what were basically 2 popular vote ties (advantage PSC), CiU still held the most seats. Interestingly, while in 1999 they were able to keep the government, they were ousted in 2003 by a 3 party coalition (PSC, the secessionist ERC and ICV, the commie-greens brand in Catalonia)
Because of the independence issue the Catalan electoral system has come under a lot of criticism by unionists since it favours secessionists.
Basque Country, 1986 (75 seats)
PSE: 22.0% (19)PNV: 23.6% (17)https://en.wikipedia.org/wiki/Basque_regional_election,_1986Again, malapportionment. The Basque Parliament, surprisingly gives the same amount of seats (25) to each of the 3 Basque provinces, even though Álava has around a quarter of Bilbao's population and around half of Guipúzcoa's.
Interestingly, this malapportionment actually works against the nationalist's favour, unlike in the Canary Islands/Catalonia, as Álava has always been the most unionist and culturally Spanish province. PNV was also suffering from infighting on that election, with a very powerful split (EA), which was strong in Guipúzcoa, leaving PNV with only their Vizcaya base (the underrepresented province). So even though PSE lost the popular vote they won the most seats. To this day it's still the only time PNV hasn't had the largest amount of seats, even when they were ousted in 2009 they still held the largest amount of seats.
End result is that PSE and PNV form a coalition government, but that the government would be led by the popular vote winner (PNV).
Interesting how in all cases there are nationalist parties involved.