Spain's Prime Minister Pedro Sanchez poses after winning the parliamentary vote following the investiture debate at Parliament in Madrid, Spain, January 7, 2020. REUTERS/Stringer SPAIN-POLITICS/ | STRINGER

Spanish Socialist leader Pedro Sanchez secured parliamentary backing by a wafer-thin majority today to form a coalition government, ending a lengthy political stalemate.

After nearly a year of caretaker governments, Sanchez won the simple majority he needed by two votes with the support of lawmakers from smaller regional parties.

He and coalition ally Pablo Iglesias, the leader of left-wing Unidas Podemos, have said they will push for tax increases on high-income earners and companies and roll back labour reforms passed by a previous conservative government.

But without a solid majority in parliament, the coalition may struggle to pass legislation and will need to negotiate with other parties on a case by case basis.

"I trust that we can overcome the atmosphere of irritation and tension and that we can recover a space for consensus and for agreement," Sanchez told parliament ahead of the vote.

Politicians had accused each other of pressuring lawmakers, in particular from small regional parties that said they would back Sanchez, to change their minds.

But in the end the vote passed off with no surprises.

Sanchez won the backing of 167 of the 350 lower house legislators, while 165 voted against. The remaining 18 abstained.

Sanchez's Socialist party, which came first in two inconclusive national elections in 2019, had failed until today to get parliament's backing and had in the meantime led a caretaker government that had little margin to push through policies.

The rise of new parties in Spain over the past five years has ended decades of dominance by the Socialists and conservative People's Party over Spanish politics, making the process of forming governments and keeping them in power far harder.

Together, the Socialists and Podemos have just 155 seats in the highly fragmented 350-seat parliament.

Their coalition was voted in thanks to some of the smaller parties, including the Catalan separatists of Esquerra Republicana de Catalunya (ERC), who abstained.