Swedish Social Democratic Party leader Magdalena Andersson will get a second shot at becoming the country's first woman prime minister next Monday, after her first attempt lasted just seven hours.

Parliament on Wednesday elected Andersson as prime minister, but she resigned just hours later -- before she even had a chance to formally take office -- after the Green Party quit the coalition government.

Speaker of parliament Andreas Norlen said he "deeply regretted" Wednesday's turn of events, which the media described as a "nightmarish day".

"This kind of behaviour risks hurting the people's trust in parliament and politics," Norlen said.

Andersson, 54, is expected to form a minority government made up solely of the Social Democrats, less than a year ahead of September general elections.

The unprecedented situation arose when Andersson secured a last-minute deal with the Left Party to raise pensions in exchange for its crucial backing to get her elected as prime minister.

But that agreement did not sit well with the small Centre Party, which withdrew its support for Andersson's budget due to the concessions made to the Left.

That left Andersson's budget with insufficient votes to pass in parliament.

Lawmakers instead adopted an alternative budget presented by the opposition conservative Moderates, Christian Democrats and far-right Sweden Democrats.

Andersson grudgingly said she would still be able to govern with that budget, but the Green Party said it could not tolerate a "historic budget drafted by the far-right" and quit the government.

That meant Andersson had to resign, as the basis on which she was appointed no longer existed.

Andersson is expected to form a minority government made up solely of the Social Democrats, less than a year ahead of September elections
Andersson is expected to form a minority government made up solely of the Social Democrats, less than a year ahead of September elections AFP / Jonathan NACKSTRAND

An economist who has served as finance minister for the past seven years, Andersson took over as leader of the Social Democrats on November 4 from Stefan Lofven.

He resigned as prime minister a week later, afer seven years in power, in order to give her time to prepare for the September elections.

Her appointment by parliament next week is expected to go ahead unhindered, as the parties that supported her on Wednesday -- the Centre, Greens and Left -- have all said they would do so again.

However, she will face a difficult 10 months running up to the election, where crime and immigration are expected to top Swedes' concerns.

She will head a weak minority government whose room to manoeuvre will be limited by the opposition's budget.

Nicknamed "Bulldozer" by the media for her direct and blunt style, she has listed her political priorities as moving away from the recent privatisation of the welfare sector -- schools, healthcare and elderly care -- and making Sweden a global role model in climate transition.

She has also vowed to end the segregation, shootings and bombings that have plagued the country in recent years, usually due to gangland rivalries or organised criminals battling over the drug market.

Despite being a nation that has long championed gender equality, Sweden has never before had a woman as prime minister.

After her election Wednesday, Andersson called it "a special day", coming 100 years after the Scandinavian country allowed female suffrage.

All other Nordic countries -- Norway, Denmark, Finland and Iceland -- have seen women lead their governments.