(Bloomberg) -- After the longest political standoff in its history, Sweden finally has a government.

The parliament in Stockholm voted to let Social Democrat Stefan Lofven become prime minister. He will lead a coalition that straddles both sides of the political divide, but that keeps the nationalist Sweden Democrats away from the levers of power.

“In times when right-wing extremist forces are growing in many countries, Sweden has chosen another way forward,” said Anders Ygeman, who is group leader for the Social Democratic Party.

The development brings to an end more than four months of uncertainty in a country usually associated with high levels of political stability. Markets had responded with relative calm to the stalemate, thanks to a well functioning government apparatus behind the scenes, but a lot was resting on Lofven’s success. If he’d failed, Sweden would have faced a snap election, and a very uncertain future.

Relief

“It’s a relief that the threat of a snap election this spring has disappeared,” said Henrik von Sydow, a strategist at Carnegie who also used to be a lawmaker for the opposition Moderate Party. “That would definitely have been an additional risk for investors.”

It’s likely to go down in Swedish history books as a near escape. The Sept. 9 election was inconclusive, and the two biggest parties -- the Social Democrats and the Moderates -- both refused to concede defeat. As the establishment blocs struggled to deal with the new reality, the Sweden Democrats -- with their neo-Nazi roots and euro-skeptic policies -- appeared to emerge as the ultimate kingmakers. The party, which inside parliament has a near pariah-status, had secured almost a fifth of the popular vote.

Among the more established parties, there was a tacit agreement to keep the Sweden Democrats out of any coalition. But the jury is still out as to whether the nationalists can be excluded from influence in the long run.

For now, Lofven needs to ensure he satisfies the centrists without alienating the left. The Center Party and the Liberals want to cut income taxes. The Social Democrats have tended to be ideologically opposed to such a step but have now struck a compromise. The joker remains the Left Party, which has made clear it’s ready to veto policies it doesn’t like, though it won’t have enough clout to derail Lofven’s budget proposals.

Ulf Bjereld, a professor of social sciences at the University of Gothenburg and a member of the Social Democratic Party, says he thinks “things are going to be less dramatic going forward than many expect.” The drawn-out negotiations ultimately mean that “they’ve had time to think it through. Also, it’s not like there is another government alternative.”

Law and Order

Meanwhile, Lofven’s four-party agreement doesn’t make many concessions to voters worried about law and order, or immigration. The question is whether that’s wise, given the clear signal from the electorate that those issues are of concern for many Swedes.

Jimmie Akesson, who leads the Sweden Democrats, said the Social Democratic Party “hasn’t understood anything. They are returning to a policy that will increase immigration even more, the issue that was the absolutely most important during the previous term.”

The Sweden Democrats gained support as voters reacted to a surge in immigration in the wake of the Syrian refugee crisis, and polls also suggest that Swedes are concerned about a rise in crime, with extreme examples including a large number of street shootings and mobs setting cars on fire.

Carl Schlyter, a former member of the European parliament for the Green Party, criticized efforts to block any single group from influence if it’s won the backing of the people.

“You can’t have the exclusion of other parties as your goal, you must have a positive common project that you believe in,” he told Swedish Radio on Thursday. If the goal is “to stop right-wing extremism, then you’ve misunderstood why these populist parties are on the rise.” Schlyter is so put out by the choices his party has made that he says he’s leaving in protest.

Per capita, Sweden let in more asylum seekers than any other European Union nation in 2015. Scandinavia’s largest economy now has a chance to show it can absorb the newcomers without giving way to a populist backlash. That will be a clear challenge facing the new government, and the rest of Europe will be watching.

(Adds comments from party leaders.)

--With assistance from Veronica Ek.

To contact the reporters on this story: Amanda Billner in Stockholm at abillner@bloomberg.net;Rafaela Lindeberg in Stockholm at rlindeberg@bloomberg.net

To contact the editors responsible for this story: Jonas Bergman at jbergman@bloomberg.net, Tasneem Hanfi Brögger, Niklas Magnusson

©2019 Bloomberg L.P.