Sweden's parliament has elected Prime Minister Stefan Lofven to a second four-year term ending more than four months of political deadlock.

Friday's confidence vote came after numerous failed attempts at creating a government since inconclusive elections in September.

The Social Democratic leader is set to form a minority government with the Greens. He is expected to formally present his new government and its full programme on Monday.

Lofven, 61, brought together parties from the centre-right and centre-left last week in order to prevent the anti-immigration Sweden Democrats, which came third with 17.6 percent of the vote, from having a voice in policy-making.

His government will be one of the weakest in Sweden in 70 years with just 32.7 percent of voters casting ballots for the two parties.

The ex-communist Left Party had backed Lofven's previous minority government since 2014, providing key support to pass legislation in parliament.

But this time, the Left Party, which now holds 28 seats, was excluded as Lofven shifted his government towards the centre.

To block the far-right Sweden Democrats from wielding any influence in parliament, the Left Party announced it would still allow Lofven to be elected.

Under Sweden's political system, a government can operate as long as a majority of parliamentarians do not vote it down.