Sweden’s prime minister has lost a vote of confidence in parliament after an election this month stripped him of his majority.

Stefan Lofven, leader of the Social Democratic Party who has been prime minister for four years, will continue in a caretaker role until a new government can be formed that has the command of the Riksdagen, the national parliament.

Legislators voted 204-142 against Mr Lofven. Three were absent, so did not vote. The ballot was mandatory after the September 9 general election delivered a hung parliament.

Although Mr Lofven remains optimistic he may be able to form a government, the vote means Sweden faces weeks of political uncertainty.

Stefan Lofven during the vote of confidence
Stefan Lofven during the vote of confidence (Anders Wiklund/TT/AP)

Both main political blocs in the parliament have refused to co-operate with the anti-immigrant Sweden Democrats party, which made great strides in the election.

Neither the left-leaning bloc led by the Social Democrats nor the Moderates-led centre-right opposition managed to secure a majority in the 349-seat parliament.

In the election, the Social Democrats got 28.3% of the vote while the Moderate Party received 19.8% and the Sweden Democrats 17.5%.

The centre-left and centre-right blocs control 144 and 143 seats respectively while the Sweden Democrats have 62.

Andreas Norlen, a member of the Moderates who was elected on Monday as speaker, is charged with trying to find someone in parliament who may be able to command a majority and form a government.

He alone decides which of the party leaders can begin these talks.

Mr Lofven remained optimistic he could form a governing coalition but stopped short of saying who with.

“I am available for talks,” he said after the vote on Tuesday.

He ruled out having any contacts with the Sweden Democrats, saying “time after time, their connections to racist and Nazi organisations have been exposed”.