Pedro Sánchez will continue as Prime Minister. | Juan Carlos Hidalgo

Pedro Sánchez won the backing of a majority of lawmakers in Spain’s parliament to form a new government today, bringing four months of political paralysis in Madrid to an end.

The 51-year-old premier prevailed in a vote in Spain’s hyper-fractured, 350-seat parliament, obtaining yea votes from every left-wing and separatist group. In all, 179 lawmakers backed Sánchez.

Sanchez's confirmation as premier ends four months of uncertainty since an election in July produced no outright winner. Alberto Nunez Feijoo, a candidate with the conservative Partido Popular (PP), won the most seats but failed to secure enough support from other parties in his own bid to lead the country.

The deals struck by Sanchez's Socialist Party (PSOE) include an amnesty law for Catalan separatists with pro-independence parties Junts and Esquerra Republicana de Catalunya (ERC), which has fueled a fortnight of protests and fierce condemnation from his opponents.

Unidentified attackers hurled eggs at a group of PSOE lawmakers having breakfast this morning near the Congress, prompting Jorge Pueyo, a deputy for PSOE's hard-left allies Sumar, to "resoundingly condemn this political violence for reasons of hate and those who foment it".

"They think they attack the Socialists, but no, they attack democracy," Patxi Lopez, the PSOE's parliamentary spokesperson, said of the egg-throwing incident during the debate.

Authorities said 15 people were arrested in a 2,000-person protest on Wednesday night outside the Socialist Party headquarters in Madrid following clashes with police.

Many Spaniards are angered by the amnesty bill, which would exculpate politicians and activists who took part in an attempt to separate Catalonia from Spain that reached its apex in 2017. The bill was registered in parliament on Monday.

Feijoo, who accused Sanchez of undermining the rule of law on Wednesday called for mass protests on Saturday Nov 18.

Sanchez argued on Wednesday that an amnesty would help to defuse tensions in Catalonia.

However, the composition of the new coalition will mean that passing any legislation will require "continuous negotiation and strict adherence to the agreements, especially in the case of the Catalan separatists," Thinking Heads, a Madrid-based think tank, said in a report.

While the Socialists say the deals include guaranteeing "stability" in the legislature, there is no formal agreement to support the budget. It will be negotiated "in good faith", according to a senior Socialist source.

"If progress is not made, we will not endorse any initiative put forward by your government," Junts parliamentary spokesperson Miriam Nogueras warned on Wednesday.

Sanchez will also face pressure from separatists to authorise another independence referendum.

"The commitment to independence is unwavering," Nogueras said. "If anyone says that this agreement is about turning the page, they are deceiving the public."