With 94 percent of the vote counted, the socialists show a clear lead winning 122 seats, well short of an overall majority but enough to govern if they garner the support of Podemos and smaller regional parties, including the Basques and Catalan separatists.
Far-right party Vox looked set to win 24 seats, the first time a far-right party will enter parliament since Spain's transition to democracy after the death of dictator Francisco Franco.
Support for Vox eroded the share of the right-wing Popular Party, which saw its worst result in its history, securing just 65 seats, down from from 137 in 2016 at the last general election.
Ciudadanos saw a rise in support to 57 seats up from 32 in 2016.
Podemos appeared to have seen their support crushed dropping from 71 seats in 2016 to just 42 this time.
- Why has Spain's main right-wing party lost so many votes?
- Pedro Sanchez: the phoenix of Spanish socialism
The results show that although the PSOE falls well short of the magic 176 seats need for a majority in parliament, it could form a coalition if they can win the support of Podemos, but they will also need the regional Basque and Catalan parties to back them.
The PSOE could easily form a government and avoid having to rely on the fractious support of the Catalan separatists if Pedro Sanchez can form an alliance with Albert Rivera's Ciudadanos.
The vote saw the collapse of the PP making it impossible for them to form a right-wing government even with the support of Ciudadanos and the newly emerged Vox party.
Turnout was at a record high with participation at a whopping 75 percent.