Caretaker Prime Minister Mariano Rajoy consolidated his position in Spain's general election as voters backed away from insurgent political forces in favor of the relative security of the People's Party.

The outcome of Sunday's vote confounded exit polls and suggested voters had shied away from the anti-establishment party Podemos at the last minute. With the U.K. engulfed by political and economic uncertainty following Thursday's unprecedented vote to quit the European Union, Spaniards bought into Rajoy's call not to jeopardize the country's economic recovery.

"Without doubt, Brexit has been the black swan in these elections," Ivan Redondo, a political consultant who advised Rajoy on his 2008 campaign, said by email. "Since Thursday, we've seen pro-establishment voters mobilized."