Spain is likely to install a leftwing government this week after Pablo Iglesias, leader of the anti-austerity Podemos, agreed to step aside to enable a coalition between his party and the Socialist Workers’ party, led by Pedro Sánchez.

Months of wrangling since April’s general election came to a head last week when Sánchez said he was prepared to form a coalition on the condition that Iglesias did not have a ministerial position. He said Iglesias was “the principal obstacle” to agreeing on a coalition, adding that other Podemos members would be offered cabinet positions. Among those tipped to join the government is Irene Montero, the party’s number two, who is also Iglesias’s partner.

“We are convinced we are going to reach an agreement in response to the millions of people who voted on 28 April for a progressive government,” Adriana Lastra, the Socialist party spokeswoman, said.

“Over the next few days we will work with discretion and loyalty with the aim that next week the country will have a functioning government,” she added. “We are going to talk about the program and the reforms the country needs.”

Facebook Twitter Pinterest Podemos’s Pablo Iglesias will have no ministerial role in the new coalition government. Photograph: Rafael Marchante/Reuters

Sánchez’s stated reason for not wanting Iglesias in the government is the latter’s support for a referendum on Catalan independence and his insistence that the leaders who have been in custody for nearly two years while on trial for their part in the unilateral declaration of independence in 2017 are political prisoners.

Last week the Catalan president, Quim Torra, said his party would support Sánchez’s investiture only if he promised to hold a referendum, to which Sánchez reiterated that a referendum would be unconstitutional. Sánchez, dismissed by many as a handsome guy in a suit, has proved a much wilier politician than most suspected. First, he took everyone by surprise when his vote of no confidence brought down Mariano Rajoy’s corrupt government last year. Now, after he risked dragging the nation into its fourth general election in four years, the Podemos leader ended up the first to blink.

The Socialists won 123 seats in the election, 38 more than in 2016, while Podemos won 42. This leaves the coalition 11 seats short of the 176 needed for an absolute majority. Sánchez is hoping to make up the numbers with Basque nationalists and independents, without having to rely on Catalan separatist parties.

The first vote on the investiture will be held on Tuesday. If Sánchez fails to secure an absolute majority there will be a second vote on Thursday. On that occasion he only needs a simple majority in order to form a government.

Assuming it all goes ahead, the coalition government will have to deal with a country that is still hauling itself out of recession. Overall unemployment stands at around 14%, and more than twice that for 18-24-year-olds. Meanwhile, there is growing unrest in Madrid and Barcelona over soaring rents, street crime and over-tourism, not to mention the perennial and intractable Catalan question.

But Sánchez is ambitious, both for himself and his country, which he wants to position as a leading force in southern Europe. After years of stagnation, Spain is now waiting to see if his campaign slogan “make it happen” has any substance.

• This article was amended on 22 July 2019 to clarify the timetable for the investiture votes.