IN ITS second general election in six months, Spain has moved much closer to breaking its political deadlock. The big winners in the vote on June 26th were Mariano Rajoy, the prime minister, and his centre-right People’s Party (PP). The PP did not recover the absolute majority it lost in December. But it gained both votes and seats compared with then, winning 33% of the vote (up from 29%) and 137 seats in the 350-member Cortes (parliament).

Mr Rajoy now looks likely to remain prime minister, but at the head of a coalition. “We claim the right to govern,” he told several thousand jubilant supporters.

The biggest losers were the pollsters. They wrongly predicted that Podemos, a radical new left-wing party, would overhaul the centre-left Socialist Party. In the event the Socialists clung on to their position as the largest force on the left, winning 22.7% of the vote and 85 seats (down five). That result is probably enough for Pedro Sánchez, the much-criticised Socialist leader, to keep his job, at least for the time being.

For this election Podemos, which campaigned against austerity and the traditional political class, merged with the old Communists of the United Left (which won 3.7% of the vote in December). But the merged force won precisely the same number of seats (71) as its constituent parts did last time. The long faces of Podemos’s young leaders reflected dashed expectations. Their political insurgency may have hit its ceiling, though its support among younger voters gives it cause for hope.

Ciudadanos, a new liberal party which won 32 seats (down eight), paid the price for having tried to form a government with Mr Sánchez after the December election. Some of the former PP voters who had supported it switched back as a result.

Two other factors seem to have helped the traditional parties. The first was the turbulence prompted by Britain’s decision to leave the European Union; the Madrid stock exchange index fell by 12.4% on June 24th. This seems to have dissuaded some Spaniards from adventures. Secondly, the turnout was almost four percentage points lower than in December. That may have helped the PP.

Mr Rajoy became prime minister in 2011 with Spain deep in recession. He has set it on the path to economic recovery, by cleaning up the banks and reforming the labour market. Budget cuts and corruption scandals hurt the PP, but it has proved resilient. “This has not been an easy phase,” Mr Rajoy admitted.

In appearance stolid and unimaginative, Mr Rajoy is unflappable and a shrewd strategist who has repeatedly defied rivals and expectations. He will now start talks to try to patch together a majority.

How strong a government Spain gets will depend on these negotiations. Albert Rivera of Ciudadanos has called for Mr Rajoy to step down as the price of his backing for a PP government, but the results mean he is hardly in a position to enforce that. The support of Ciudadanos and moderate regional parties would put Mr Rajoy within one seat of a majority. The prime minister would prefer the Socialists to join him in a German-style “grand coalition”. Mr Sánchez has hitherto rejected that: the left-right divide has been deep and unbridgeable throughout modern Spain’s political history.

A third election to break the deadlock is hardly in the interests of Mr Sánchez or Mr Rivera—or of Spain. The country needs change, if it is to consolidate economic recovery, deter Catalan separatism and shore up public confidence in the political system. A grand coalition would be best placed to deliver it.