STOCKHOLM -- Sweden's prime minister lost a vote of confidence in parliament on Tuesday after an election this month stripped him of his majority.

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

Lawmakers voted 204-142 against Lofven. Three lawmakers were absent, so did not vote. The vote was mandatory after the Sept. 9 general election delivered a hung parliament.

Although Lofven remains optimistic that he may be eventually able to form a government, the vote means that Sweden faces weeks of political uncertainty. 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 per cent of the vote while the Moderate Party received 19.8 per cent and the Sweden Democrats 17.5 per cent. The centre-left and centre-right blocs control respectively 144 and 143 seats while the Sweden Democrats have 62 lawmakers in the assembly.

Andreas Norlen, a member of the centre-right Moderates who was elected Monday as speaker, is charged with trying to find someone in parliament who may be able to command a majority and to form a government. He alone decides which of the party leaders can begin these talks.

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

"I am available for talks," Lofven said after the vote Tuesday.

Lofven ruled out having any contacts with the Sweden Democrats, saying "time after time, their connections to racist and Nazi organizations have been exposed."