Sweden’s prime minister has lost a vote of confidence in parliament, meaning he will have to step down – though not immediately.

Stefan Lofven, the leader of the Social Democratic Party, will continue as caretaker prime minister until a new government can be formed that has the command of the Riksdagen.

Politicians voted 204-142 against Mr Lofven, while three abstained.

Mr Lofven has been prime minister since 2014.

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

Tuesday’s vote was mandatory after elections earlier this month delivered a hung parliament.

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 after the September 9 vote.

Both have refused to co-operate with the anti-immigration Sweden Democrats.

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 legislators in the assembly.

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.

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