Mariano Rajoy, Spain’s caretaker prime minister, boosted his prospects of remaining in office when, after eight months of deadlock, a centrist party agreed to back him in parliamentary confidence votes this week.

The pact unveiled on Sunday between Mr Rajoy’s conservative Partido Popular and the Ciudadanos movement comes after the dogged prime minister had struggled to win the backing of any of his rivals for months.

Without further support, Mr Rajoy will have to fight a third general election within a year — following inconclusive votes in December and June that left the PP with most seats in Spain’s lower house of parliament, but well short of a majority.

But the deal with Ciudadanos, which had previously insisted on his resignation, is likely to bolster his reputation as a survivor.

Despite his failures to triumph at the last two polls, Mr Rajoy, who only won a general election at his third attempt in 2011, has ridden out a series of corruption scandals affecting in his party, remaining firmly at the helm of the PP.

On Wednesday, Mr Rajoy faces an investiture vote in parliament. With the backing of Ciudadanos he can rely on the support of 170 MPs, six short of the total he needs for an absolute majority. If he loses, which is widely expected, a second vote on Friday would take place in which he would require just a simple majority.

With the opposition Socialist so far refusing to countenance even abstaining in Friday’s vote, Mr Rajoy looks likely to fail and on Saturday conceded that the prospect of forming a government was “more a wish than a fact”.

The failed investiture votes would trigger the countdown to fresh elections, which could fall on Christmas Day.

Mr Rajoy lost his majority last December amid allegations of slush funds run for party members and kickbacks from construction contracts that helped persuade voters to back fledgling parties such as Ciudadanos and the leftwing Podemos party.