LISBON — Prime Minister António Costa consolidated power in Portugal as his Socialist Party (PS) won big in city hall elections nationwide, again bucking the trend of a center-left decline in the rest of Europe.

“Today, the PS has had the biggest electoral victory in its history,” Costa declared as the results came in on Sunday. “This is a great victory across the whole country.”

The Socialists captured a record haul of 158 town halls out of the country’s 308 cities and towns.

The party held Lisbon and won nine of the 15 most populous cities. A rare disappointment was a failure to take the mayor’s office in second city Porto from a popular centrist independent.

Nationwide, the Socialists' vote share topped 38 percent, up from 32.3 percent in the 2015 parliamentary election.

The vote was a disaster for the main center-right opposition, the Social Democratic Party (PSD), which was pushed into a humiliating third place in Lisbon and Porto. It won just 96 city halls, compared to 106 in the last election in 2013.

Social Democrat leader Pedro Passos Coelho looks unlikely to survive. He is expected to face a leadership challenge, perhaps as soon as Tuesday, when the party’s national council meets to dissect the defeat.

Passos Coelho — who served as prime minister from 2011 until he was unseated by Costa in November 2015 — acknowledged the defeat was one of his party’s worst ever, but said he had no plans to resign.

Party bigwigs, however, were sharpening their knives.

“I wouldn’t be surprised if Pedro Passos Coelho says he’s leaving today, or on Tuesday,” former Social Democrat leader Luís Marques Mendes told the SIC television network. “If he doesn’t, his life is going to be hell.”

Damage to the left

The Socialists didn’t only grab votes from the right.

The Portuguese Communist Party (PCP) — which backs Costa’s minority government — lost 10 town halls to Costa's Socialists, holding just 24.

A night of shocks for the Communists included the loss of traditional strongholds of Almada and Barreiro in the red belt of industrial suburbs south of Lisbon and the rural fief of Castro Verde, which the Communists had held since the 1974 revolution that made Portugal a democracy.

The other far-left party in the governing alliance — the Left Bloc — failed to capture any councils, and scored just 3.3 percent across the country.

Conversely, the far left's discomfort could make life more difficult for Costa — if the Communists and Left Bloc decide to shore up their base, taking a harder line in ongoing discussions with the government on next year’s budget. They were already demanding more social spending, wage and pension increases, and tax cuts for the lower paid in response to months of rosier economic data.

Costa was careful not to gloat at the Communists’ setback. "Our victory is not a defeat for any of our parliamentary partners,” he told reporters. “These results strengthen the PS, but also the whole majority in parliament that has brought change.”

The Socialists have been riding high on rising economic growth spurred by exports and tourism. That’s allowed the government to roll back some of the unpopular austerity measures imposed by the previous Social Democrat government, while simultaneously cutting the budget deficit to a record low.

“This incredible victory of the PS is a great triumph for António Costa, but it might turn out to be a victory that’s too good,” wrote Pedro Santos Guerreiro, director of the weekly Expresso newspaper. He said the far left’s poor showing would weaken the cohesion of the governing coalition. “It will be easy for the PCP to attack the government … No more being passive, no more friendly PCP.”

Costa could also face tougher opposition from a new Social Democrat leader, less tainted in voters' minds with the austerity policies of Passos Coelho’s government.

The prime minister had played a prominent role in the final days of campaigning, crisscrossing the country to join Socialist mayoral candidates on the stump, in what could be a trial run for a bid to secure an absolute majority in the next legislative elections scheduled in two years’ time.

In Lisbon, Socialist Mayor Fernando Medina was reelected with 42 percent of the vote, but lost his absolute majority as support surged for Assunção Cristas, the leader of a smaller conservative force, the CDS-People’s Party, which came second, with more than 20 percent. Social Democrat candidate Teresa Leal Coelho languished on just 11 percent.

Porto Mayor Rui Moreira, a centrist independent, was comfortably reelected with 45 percent of the vote ahead of a Socialist challenger on 28 percent and the PSD on just 10 percent.

In Loures, a town of 200,000 on the outskirts of Lisbon, the PSD fielded a candidate, André Ventura, denounced as a far-right populist by opponents after derogatory comments about the local Roma minority.

Costa had expressed fears that Ventura’s campaign could be a “trial balloon” signaling an opposition shift to the radical right. On election day, the controversial politician finished third, well behind Communist and Socialist candidates, but he scored 21 percent, increasing the party’s vote share.