Spain will be led by a coalition government for the first time in 80 years after the acting prime minister, Pedro Sánchez, narrowly secured parliamentary approval for a joint administration between his Socialist party and the anti-austerity Unidas Podemos alliance.

The investiture vote on Tuesday, which Sánchez won by 167 votes to 165, with 18 abstentions, ends the nine months of political deadlock resulting from two inconclusive general elections last year.

Sánchez’s Spanish Socialist Workers’ party (PSOE), which finished first in both elections but fell well short of a majority on each occasion, moved quickly to reach a governing pact with Unidas Podemos after the poll in November.

Key to Sánchez’s tight victory was the abstention of the pro-independence Catalan Republican Left party (ERC), which agreed to sit out the investiture vote after Sánchez vowed to find a solution to the “political conflict” that has dogged Spain since Catalonia’s separatist regional government tried to secede in 2017.

Sánchez and his party have insisted that the negotiations will have to respect the constitution and stressed their commitment to maintaining Spain’s territorial unity.

The ERC soon made it very clear the new central government should not take its support for granted, with the MP Montserrat Bassa telling congress she “didn’t give a damn about the governability of Spain”.

Bassa’s sister, Dolors Bassa, was one of the Catalan leaders jailed in October by Spain’s supreme court over their roles in the failed push for regional independence in autumn 2017. Nevertheless, the ERC kept its word and abstained from the lunchtime vote.

The PSOE and Unidas Podemos have promised their joint government will increase the minimum wage, raise taxes on higher earners and big companies, and overhaul some of the labour changes introduced eight years ago when the conservative People’s party (PP) was in power.

In a tweet sent after the vote, Sánchez wrote: “With the progressive coalition government, Spain is entering a time for the defence of dialogue and useful politics. A government for all people that broadens rights, restores co-existence and fights for social justice. Today is the dawn of a time of moderation, progress and hope.”

Sánchez’s opponents argue his “Frankenstein government” will be too beholden to Catalan separatists and pose an existential threat to Spain’s national unity.

While the Socialist leader appealed for calm and consensus, and called on MPs across the political spectrum to “overcome the atmosphere of irritation”, his adversaries again went on the offensive.

The PP leader, Pablo Casado, accused Sánchez of being an egotistical “extremist” who had left the country’s future in the hands of “terrorists and coup-mongerers” from Catalonia and the Basque country.

“Mr Sánchez, your only homeland is yourself. Instead of being a statesman, you’ve chosen to become a straw man for nationalism,” he said.

During the weekend’s intemperate first investiture debate, Casado had branded Sánchez a “sociopath”.

The PSOE and Unidas Podemos said the PP, the far-right Vox and the centre-right Citizens party were indulging in hyperbole and scaremongering.

Pablo Iglesias, the leader of Unidas Podemos, called on his governing partner to respond to such intolerance with courtesy and “democratic resolve”.

The session on Tuesday, however, was again largely lacking in the former. MPs from the pro-independence Together for Catalonia abandoned the chamber when Vox spoke, while Vox boycotted the address by the leftwing separatist Basque party EH Bildu.

But Tomás Guitarte, the sole MP for Teruel Exists – a party that campaigns to improve conditions in the overlooked eponymous region of eastern Spain – received an ovation for voting after receiving threats over his decision to back the coalition.

Aina Vidal, an MP from Catalonia who took part in the vote despite having cancer, was also honoured with tributes and an ovation.

The PSOE took power in June 2018 after using a motion of no confidence to unseat the PP government of Mariano Rajoy, which was tarnished by a series of corruption scandals.

But the Socialists have also been tainted by corruption. Nine days after the PSOE’s election victory in November, two of its former presidents in the southern region of Andalucía were found guilty of misconduct and misuse of public funds over their roles in a decade-long, €680m (£580m) fraud that led to one of Spain’s biggest corruption trials.

Despite the new coalition’s ambitious social agenda, it is likely to find itself more preoccupied with the Catalan question and facing aggressive opposition from rightwing parties in a dramatically fragmented political landscape.

Last April’s election was triggered after the ERC and Together for Catalonia sided with their enemies on the Spanish right to torpedo the PSOE’s national budget.

The PSOE won 120 seats in November - three fewer than in April. The PP rallied in the second election of 2019, to take 89 seats, while Vox’s seat count more than doubled in November, rising from 24 to 52.

Podemos came fourth with 35 seats, followed by the ERC with 13 seats. Citizens slumped to sixth place, the 57 seats it picked up in April dwindling to just 10.