Antonio Costa's government received praise for combining fiscal discipline.

Portugal's ruling Socialists won Sunday's parliamentary election but fell short of an outright majority, meaning Prime Minister Antonio Costa will need to negotiate a new deal with one or both of his far-left allies in the previous legislature.

A few weeks ago, opinion polls showed that Costa, with ratings boosted by a strong economy, was within reach of a full majority. But the gap narrowed, leaving his Socialist party (PS) stronger than in the 2015 election but still needing allies.

"It's clear from this election that the PS is reinforced and the allied parties consolidated their positions," Costa, smiling broadly, told supporters chanting: "Victory! Victory".

"Since we don't have a majority alone, we have to find solutions that guarantee stability for the next four years," he said.

Costa said voters liked the 2015 deal that saw the Left Bloc and the Communists unexpectedly back his Socialists to sideline the right, and that he wanted it to continue, adding that he also meant to negotiate with the upstart People-Animals-Nature (PAN) party.

With most of the votes counted, the Socialists led with 106 seats. That put them in first place, but with only four seats still not accounted for, they cannot reach the full majority of 116 seats in the 230-seat assembly.

The Socialists substantially increased their score from their 86 lawmakers in 2015.

Costa's minority government has received praise from Brussels and at home for combining fiscal discipline with measures to promote growth after recession and the austerity of Portugal's 2010-14 debt crisis.

He told supporters he would continue to cut the budget deficit and the debt. But that could be complicated by his potential allies' demands.

"These negotiations could be more complex than four years ago when the pact on the left was cemented by their common goal to unseat the right," said political scientist Antonio Costa Pinto.

"Now the left as a whole has been reinforced. ... Obviously they will test the budgetary limits and the economic projections for the next few years," Costa Pinto said, expecting the negotiations to take a few weeks, now with more participants.

President Marcelo Rebelo de Souza is likely to demand assurances from the parties that the solution would be a lasting one.

Negotiations are in any case not expected to be as messy or as long as in neighbouring Spain, which still has no government more than five months after elections and is heading for a repeat vote in November.

In 2015, it took less than two months for Costa to reach a deal with leftist allies and be sworn in as prime minister.

'NO OBSTACLE'

Leaders for the Left Bloc and the Communists both said they had no objections to Costa being nominated as premier and were open to negotiate if the Socialists committed to improving the lives of workers.

"There is no obstacle for the president to appoint the prime minister and for the government to be formed and start working," said Communist leader Jeronimo de Souza. "We will determine our position depending on the PS' choices, on its budget instruments and the content of its legislative proposals."

Costa has benefited from an economy that is growing more than the EU average, helped by increased exports and a booming tourism industry that last year saw visitors outnumber Portugal's inhabitants.

But a series of scandals, from a nepotism row to the alleged involvement of a former minister in an army cover-up of the theft of weapons from a military base, has hit the Socialists' ratings.

The main opposition Social Democrats (PSD) won 28% of the votes and at least 77 seats, according to the preliminary results, once of their weakest results ever.

'WE GOT STRONGER'

At the PS election rally, supporters stood up cheering as the exit polls were published.

"We got stronger from this election and we will be able to continue with our policies," said 25-year-old supporter Miguel Matos.

PAN attracted more votes than in the previous election, riding a wave of popularity among pro-environment parties in much of Europe to land at least four seats. But those seats are not enough for the Socialists to govern with them alone.

"It's a very good result. I still wish it was more, because the country needs to move quickly to tackle the climate emergency," PAN supporter Paulo Santos, 43, said at the party's evening rally.

The far-right Chega elected one lawmaker - the first time a far-right party got a seat in Portugal's parliament since the end of the dictatorship in 1974. Two other small parties got one lawmaker each for the first time.