Portugal's right-wing coalition won October elections but lost the absolute majority it had enjoyed since 2011 – the exact same situation that Spain's conservative Popular Party (PP) now finds itself in after December 20th polls.
The current political limbo has left Spanish Prime Minister Mariano Rajoy scrambling to get support from Sanchez's Socialists (PSOE), which came second, to form a government.
But the PSOE has categorically refused to get into bed with the PP, and Sanchez's meeting with Portuguese Prime Minister Antonio Costa is aimed at studying the country's recent experience, a Socialist source said.
The source added Sanchez wanted to “find out how (the current government) was formed and how it's going now.”
After winning the October elections, Portugal's Prime Minister Pedro Passos Coelho was eventually forced to resign when his minority government was toppled by a leftist alliance led by the Socialist Party.
In Spain, a similar left-wing coalition composed of the PSOE, upstart anti-austerity party Podemos and smaller, regional nationalist groupings would be possible and if formed, would be able to bring down the conservatives.
But the PSOE is deeply divided over the issue.
On Thursday, several lawmakers on the left of the Socialist party wrote an open letter to Sanchez, calling for an alliance with Podemos – an ally of Greece's Syriza that emerged just two years ago on the back of exasperation over austerity and corruption.
“A left-wing pact is essential for the policies of social reconstruction that our country needs, such as the fight against unemployment that would involve new economic policies and the defence of the welfare state,” they wrote in the online daily eldiario.es.
And while Sanchez is considering such an alliance, others such as the all-powerful Socialist chief of the southern Andalucia region, Susana Diaz, are thought to be more reluctant.
These divisions in Spain's Socialist camp were sharply criticised in a Thursday editorial in the left-wing daily El Pais, which accused its leaders of making a “spectacle” of themselves.
“Not only is that undermining the possibility of forming a government for change, but it's also putting in danger the very survival of a party with more than 100 years of history,” it wrote.