Portugal's president on Tuesday charged incumbent Prime Minister Antonio Costa with forming a new government after his Socialist party fell just short of a parliamentary majority in elections.

"The most important question is that of stability," Costa, the former mayor of Lisbon, said after meeting President Marcelo Rebelo de Sousa on Tuesday evening.

The announcement came after Rebelo de Sousa met the leaders of smaller parties earlier in the day.

The Socialists strengthened their position in parliament in Sunday's polls, winning 106 seats in the 230-seat assembly, up from 86 seats but still 10 shy of an outright majority.

The election result is incomplete as four seats must still be attributed according to votes cast abroad, which are yet to be counted.

Costa, who campaigned on a promise to boost disposable income while protecting public finances, has said he aims to "renew" his alliance with the two hard-left parties that propped up his government during the past four years -- the Left Bloc and the Communists.

The Socalist party of incumbent Prime Minister Antonio Costa won the election
The Socalist party of incumbent Prime Minister Antonio Costa won the election AFP / PATRICIA DE MELO MOREIRA

But it remains to be seen what these two formations will demand in exchange for their support.

The Left Bloc won 19 seats -- the same number as in the 2015 election -- while the Communists took 12, down from 17.

The election result means Costa only needs the support of one of them to reach a majority.

Costa also has two other possible allies -- the People Animals Nature party (PAN) which had just one lawmaker in the assembly and now has four, and upstart eco-socialist party LIVRE (free), which entered parliament for the first time with a single seat.

Another option for Costa would be to forgo a formal alliance with other parties and negotiate support to pass legislation on a case-by-case basis.

Costa will open formal talks on Wednesday with potential partners, according to media reports.

Under Costa's watch the country's budget deficit fell to nearly zero, the lowest level since Portugal returned to democracy in 1974.