Pedro Sanchez , the leader of Spain’s main opposition Socialist Party resigned on Saturday night after losing a long battle against other senior party members who were opposed to prolonging the deadlock in Spanish politics which has led to hopes for an end to Spain’s its nine-month wranglings which have risen after the shattered Socialist Workers’ party deposed its leader over his pointblank refusal to allow the acting prime minister to form a government.

His plan to hang on to his job by holding a leadership contest in three weeks’ time was eventually rejected by 132 votes to 107 at the end of an 11-hour session that laid bare the utter chaos at the heart of the PSOE.

Spain has been without an elected government since an inconclusive election in December. Mr. Sánchez had refused to allow Mariano Rajoy, the caretaker prime minister, to start a new term, arguing that Mr. Rajoy was unfit for office largely because of corruption scandals that have tainted his conservative Popular Party.

Sánchez had consistently argued that the party would not do anything to support or facilitate the return to government of Mariano Rajoy’s conservative People’s party, on the grounds that the PP had wrought too much damage on Spanish society It was a stance that infuriated not only many voters – and the media – but also his adversaries within the PSOE who blamed him for the party’s disastrous electoral performance.

Mr. Rajoy, however, has insisted that he should stay in charge after his party twice won national elections — in December and June — but both times without a parliamentary majority.

Mr. Sánchez lost on Saturday by a vote of 133 to 109. The Socialist leadership will be taken over by a caretaker management committee whose first task is likely to be to confirm whether the Socialists will change tack and no longer block Mr. Rajoy’s re-election.

The PSOE now has a month to regroup and re-evaluate its position before King Felipe could dissolve parliament and call new elections to be held at Christmas.

The committee must also begin the difficult job of reuniting a Socialist Party battered by election defeats and fractured by the tussle to remove Mr. Sánchez. Susana Díaz, the Socialist leader of the southern region of Andalusia, pushed to oust Mr. Sánchez and is seen as the front-runner to eventually succeed him.

Mr. Sánchez tried unsuccessfully this year to form a government of his own, in coalition with Ciudadanos, a smaller centrist party that has since switched its support to Mr. Rajoy.

“I always thought the Socialist Party should provide an alternative,” Mr. Sánchez said at a news conference on Saturday. “Unfortunately it didn’t prove possible during the last legislature.”

It appears that the PSOE had been wounded from this  week’s events and not capabable of third elections in which they would suffer even further.

Reports suggest the PP will ask the socialists for far more than just a smooth investiture. Safe in the knowledge that he could use fresh elections to crush his party’s longstanding rivals, Rajoy is likely to extract the maximum possible gains from any deal. What is likely is that Rajoy will be looking for their support to make sure he has an easy tenure in office