Sweden's parliament has voted to re-appoint caretaker prime minister Stefan Löfven to lead a new government.
The leader of the Swedish Social Democratic Party was backed by the Green Party to give Löfven the exact number needed to secure a majority.
173 MPs voted against Löfven, in a debate that came just sixteen days after the former prime minister resigned.
Löfven stepped down as prime minister after losing a historic no-confidence vote on June 21 over proposed legislation to tackle a housing shortage.
Until then, he headed a minority government made up of a coalition between the Social Democratic and the Greens.
Instead of calling an early election, the former PM chose to open coalition talks, which are overseen by Sweden's parliamentary speaker, Andreas Norlén.
But after other parties failed to find support to form a government, he was asked to return to his post.
On Monday, Norlén had declared that the Social Democrat leader had enough backing in the 349-seat Riksdag to form a two-party Cabinet.
Löfven is now expected to formally present his new coalition government on Friday.
"Stefan Löfven has a solution that can be tolerated by the Riksdag,” Norlén told a news conference on Monday. "I will therefore appoint him as a prime ministerial candidate.”
Löfven, who has served as Sweden’s head of government since 2014, remained as caretaker prime minister after resigning.
He only returned as Sweden's Prime Minister in 2019 after four months of negotiations following the 2018 parliamentary elections.
Last week, Sweden's opposition Moderates party failed to find support to lead a government. Ulf Kristersson, leader of the party, said last week that could only rely on the support of 174 Swedish lawmakers.
Had Löfven lost Wednesday's vote, Sweden might have been forced to hold snap elections for the first time since 1958. The next general election in the country is scheduled for September 2022.