The Socialists' 120 seats, combined with the 35 won by Unidas Podemos, leave them short of a majority in the 350-seat parliament.
Since the country's transition to democracy in 1976, Spain has not had a coalition government.
"Spain needs a stable government, a solid government", Sanchez said, adding they would call on other parties to join the deal.
"We have reached a pre-agreement to form a progressive coalition government combining the experience of Psoe and the courage of Unidas Podemos", Iglesias told a joint press conference with Sanchez. The market has always looked less favourably on a coalition between the Socialists and Podemos than a centre-right coalition.
Nuria Alvarez, analyst at Madrid-based brokerage Renta 4, said scepticism remains over whether the preliminary agreement would amount to a working government.
The two have been at odds for months, with party leaders exchanging harsh words as the acrimonious talks collapsed.
The two will have to strike deals chiefly with regional parties and smaller leftist groups.
Even Warmer Monday, Before Rain and Cold
A comfortable day is on tap Monday as temperatures remain near normal, but you'll want to enjoy those conditions while they last. Another mild day is on tap Monday as highs soar into the upper 50s with increasing clouds throughout the day.
The two parties signed a coalition deal in front of television cameras and even hugged at the end. The ERC's 13 seats would be essential to pass a government.
Announcing the new tentative deal, Sanchez said the aim was to break months of political deadlock. But their support will accentuate the divisions within the Spanish left over the question of autonomy and the right to self-determination of Spain's constituent nationalities.
Although the party had previously ruled out any support for Sanchez, it suffered a major rout on Sunday, prompting the resignation of leader Albert Rivera.
The two leaders have said that the coalition will form a "progressive government made up of progressive forces that are going to work for progress".
Spanish media reports said the agreement includes a role for Iglesias as deputy prime minister, something Sanchez had refused had to consider after a similarly inconclusive election in April.
Turnout was lower this time than in previous elections, and as RT's Charlotte Dubensky explained, there is voter fatigue after so many votes and government impotence.