Portugal's president named Socialist leader Antonio Costa as prime minister on Tuesday, ending weeks of political stalemate and leading to the country's first Socialist government to be backed in parliament by the far left.

Costa, the former mayor of Lisbon, was chosen by the Socialist Party for the Prime Minister's candidature in 2014 after he beat the party leader in a ballot by 70 per cent.

Before the move, President Anibal Cavaco Silva had requested written assurances from Costa that he and his parliament majority partners would respect Lisbon's commitments to EU budget rules, and the president's statement said he took notice of Costa's reply before naming him prime minister.

The statement said continuing with a caretaker government did not correspond to national interests as it would cause further political uncertainty, Reuters reported.

Earlier this month, the Portuguese parliament passed a vote of no confidence against the government of Pedro Passos Coelho, who led a centre-right coalition after elections in October. Portugal's centre-right parties won a combined 38.6% of the popular vote in the elections under the banner of "Portugal Ahead", but only held power for two weeks before being ousted, according to Business Insider.

The new government will be formed mostly of Socialist MPs, but will be propped up by the country's Communist Party and Left Bloc in a so-called "triple alliance".