STOCKHOLM (Reuters) - Sweden’s parliament handed Social Democrat leader Stefan Lofven a second term in office on Friday, ending more than four months of deadlock after an inconclusive election that had allowed a populist party to threaten the traditional balance of power.

Sweden had looked set for a snap election until last week when Lofven agreed an historic deal with the Centre, Liberal and Green parties, bringing together parties from the center-right and center-left to prevent the anti-immigration Sweden Democrats from having a voice in policy.

“Ever more governments are becoming reliant on parties with an anti-democratic agenda,” Lofven said after winning the vote in parliament. “But in Sweden we stand up for democracy, for equality. Sweden has chosen a different path.”

The Sweden Democrats polled 17.5 percent in September’s election, their support bolstered by voters’ growing concerns about immigration amid a surge in shootings and gang violence in major cities.

While Sweden will now have a workable government that will keep the nationalist Sweden Democrats from any influence over policy, Lofven faces major challenges.

SHORT-LIVED GOVERNMENT?

The deal with the Centre and Liberal parties requires Lofven, a former welder and union leader, to cut taxes and deregulate the labor and property rental market, a sharp shift to the right that is likely to alienate many of his party’s traditional supporters.

Slideshow ( 4 images )

It also brings together parties that are ideologically poles apart, raising the risk that the government will be short-lived.

The Centre and Liberals - who dumped their partners in the four-party Alliance, the Moderates and the Christian Democrats, in order to secure Lofven a second term - face a backlash from center-right voters.

“The constellation that has chosen this prime minister is only united by one thing, a democratically dubious desire to exclude other parties from influence - not to let their votes count,” opposition Moderate leader Ulf Kristersson said.

Lofven was supported by 115 law makers while 153 voted against him and 77 abstained. According to Swedish law, the nominee becomes prime minister as long as a majority of parliament does not vote against him or her.

The opposition Left Party abstained in the vote - as did the Centre and the Liberals - because it wanted Lofven reinstalled as premier, though it has threatened to cause him problems in parliament if they believe he has tacked too far to the right.

September’s election delivered a hung parliament with no major bloc able to rule without the support of the anti-immigration Sweden Democrats, a party with roots in the white-supremacist fringe.

(GRAPHIC - Election scenarios: tmsnrt.rs/2p45tJh)