The 47-year-old economist led Spain's oldest political party to two of its worst defeats in 2015 and 2016, but this time captured 124 seats in the country's 350-seat parliament according to preliminary results — short of an absolute majority but far ahead of any other party.
Given up for politically dead, Sanchez became prime minister in June 2018 after winning a surprise no-confidence vote against his graft-tainted, conservative Popular Party (PP) predecessor Mariano Rajoy with the support of the far-left party Podemos, Catalan separatists, and Basque nationalists.
He relied on this fragile alliance — dubbed a “Frankenstein government” by the conservative opposition — to govern for ten months.
- Results: Victory for Socialists but need pacts to govern
- What do the Spanish election results mean?
- Why has Spain's main right-wing party lost so many votes?
But it finally cracked in February when Catalan separatists rejected Sanchez' draft 2019 budget, forcing him to call snap polls — Spain's third general election in less than four years.
Born on a February 29 — a Leap Day — in 1972 in Madrid, Sanchez grew up in a well-off family, his father an entrepreneur and his mother a civil servant.
A married father of two daughters, he studied economics in the Spanish capital and the Free University of Brussels before obtaining a doctorate degree from a private Spanish university.
Last year, he angrily denied accusations that parts of his thesis were plagiarised.
The 1.90-metre-tall (6-foot-2) former basketball player joined the Socialist party in his early 20s. He served as a municipal councillor in Madrid between 2004 and 2009, then as a national lawmaker.
Despite being largely unknown, Sanchez won a primary election in 2014 to become Socialist party chief, beating more experienced politicians.
But several party heavyweights never warmed to him and after leading the Socialists to two consecutive general election defeats in 2015 and 2016, Sanchez was pushed out in an internal rebellion.
In May 2017, he unexpectedly won back his old job in a party primary election after driving from rally to rally in his own car. He easily defeated his main rival Susana Diaz, who was backed by virtually all of the party
During the campaign for Sunday's vote, Sanchez sought to capitalise on his experience as prime minister to present himself as the best guarantee of political stability.
The PP, Ciudadanos and upstart far-right party Vox accuse Sanchez of being a “traitor” because of his willingness to engage with Catalan separatist parties which in 2017 staged a failed attempt to break Catalonia away from Spain, triggering the worst political crisis in the country's modern history.
But he counter-attacked by warning of the risk that the PP and Ciudadanos could form a government with the support of Vox, a fierce opponent of feminism and illegal immigration, and by highlighting social measures his government adopted, such as a 22 percent hike in the minimum wage.