By Belén Carreño and Emma Pinedo
MADRID (Reuters) -Spain's conservative leader Alberto Nunez Feijoo lost a vote to form a government on Friday, clearing the way for acting Socialist premier Pedro Sanchez to seek a divisive deal with separatist parties to clinch four more years in power.
Feijoo, whose People's Party (PP) had won the most seats in July's election, narrowly failed to get a straight majority after a fractious debate in parliament.
All eyes will now turn to the Socialists, who came second in the election and are seeking the support of two Catalan parties who have demanded an unpopular amnesty for hundreds of separatists facing charges over a unilateral independence bid that came to a head in 2017.
If Sanchez's efforts also fail, there will be a repeat national election in January.
Political temperatures have risen across Spain since the vote. Crowds have jeered Catalan and Basque lawmakers going into parliament this week and shouted "Terrorists! Terrorists!" at them on Friday.
During the debate, PP lawmakers and allies in the far-right Vox party refused to wear earphones to hear translations of speeches of Catalan or Basque lawmakers. The use of regional languages, approved in parliament last week, was part of early attempts by Sanchez to court the Catalans.
House Speaker Francina Armengol ordered a pejorative reference made by a Catalan lawmaker about the national police sent to quash the 2017 independence referendum to be expunged from the record following a protest by the PP.
She also struck down comments by Vox leader Santiago Abascal, who described Sanchez as "corrupt" and "villainous".
Earlier in the day, police were called after Socialist lawmaker Oscar Puente was challenged by a fellow passenger on a train to Madrid over his party's engagement with exiled Catalan separatist leader Carles Puigdemont.
In the end, 177 legislators opposed Feijoo and 172 supported him, with one nullified vote, in a second vote on his premiership. He lost a first vote on Wednesday.
Before the vote, Feijoo had told lawmakers he knew he would lose. "I assume that, predictably, I won't get it. You can call it failure if you want," Feijoo said.
Other regional parties have refused to back him, citing his reliance on Vox and PP's long-standing opposition to giving the regions more autonomy.