* Socialists, Podemos reach preliminary deal
* Will need more allies to have majority
* Parliament very fragmented after 4th election in 4 years (Adds ERC refusal to join coalition)
By Belén Carreño and Ashifa Kassam
MADRID, Nov 12 (Reuters) - Spain's Socialists and the far-left Unidas Podemos party agreed on the basis of a coalition government on Tuesday, just two days after a parliamentary election delivered a highly fragmented parliament.
The unexpectedly fast preliminary agreement between two parties which recently refused to work together would require further steps including agreeing cabinet positions and bringing in smaller parties, which means it is far from a done deal.
The election - the country's fourth in four years - left Spain's parliament even more divided than a previous ballot in April, with the Spanish Socialist Workers' Party (PSOE) retaining its lead but further away from a majority.
"It's a deal for four years," Socialist leader Pedro Sanchez, who is currently acting prime minister, said after signing the pact alongside Podemos leader Pablo Iglesias.
The Socialists' 120 seats, combined with the 35 won by Unidas Podemos, leave them short of a majority in the 350-seat parliament.
"Spain needs a stable government, a solid government," Sanchez said, adding that they would start as soon as Tuesday to call on other parties to join the deal.
If they succeed, it would be Spain's first coalition government since the country's return to democracy in the late 1970s.
Spain's Ibex-35 index slipped by around 0.9% at 1715 GMT, having previously traded 0.3% higher on the day.
Nuria Alvarez, analyst at Madrid-based brokerage Renta 4, said scepticism remains over whether the preliminary agreement would amount to a working government.
The market has always looked less favourably on a coalition between the Socialists and Podemos than a centre-right coalition, she added.
During its campaign, Podemos opposed the privatisation of state-controlled lender Bankia, whose shares were trading 4.5% lower.
The Socialists and Podemos had tried and failed to strike a government deal after the April election, prompting Sanchez to call the repeat ballot.
The two men had been at odds for months and exchanged harsh words as acrimonious talks failed after the April election.
On Tuesday they were all smiles, hugging after they signed the pact.
"We've reached a preliminary agreement to create a progressive coalition government in Spain, which combines the experience of PSOE with the courage of Unidas Podemos," Iglesias said.
Centre-right party Ciudadanos, which won 10 seats, said it would not back the deal, calling instead for a grand coalition between itself, the Socialists and PP.
The small leftist Mas Pais party won three seats, so the two bigger leftist parties would have to draw others in to boost their combined 155-seat tally.
This means the Socialists and Podemos would need Catalan leftwing separatist Esquerra Republicana de Catalunya (ERC) to at least agree to abstain and all other non-separatist regional parties to vote in favour.
ERC, which won 13 seats in Sunday's election, said that "right now" it would not back the coalition but did not rule out modifying its position in future.
Calling on Sanchez and Iglesias to sit down with separatist politicians to try to resolve the region's political tensions, ERC spokeswoman Marta Vilalta said the ball was now in their court.
The Catalan parliament pressed its case for independence on Tuesday and protesters clashed with French riot police trying to clear them from the border.
Pablo Casado, leader of Spain's conservative People's Party (PP) criticised the coalition agreement in Madrid and called on Sanchez to resign.
"A radical government is exactly the opposite of what Spain needs right now," he said.
Local media, including news website eldiario.es, said that Iglesias would be deputy prime minister, something which Sanchez had refused in the post-April election talks. Sanchez had also at the time opposed a coalition government. The two leaders said details would come later and did not comment further. (Reporting by Belen Carreno, Jose Elias Rodriguez, Ashifa Kassam, Jesus Aguado, Elena Rodriguez, Paola Luelmo Writing by Ingrid Melander and Nathan Allen, editing by Andrei Khalip and Philippa Fletcher)