In a dramatic development, Ms Andersson, leader of the Social Democratic Party, said at a press conference: “I have asked the speaker to be relieved of my duties as prime minister.”
“I am ready to be prime minister in a single-party, Social Democrat government,” she added.
Her resignation came after her coalition partner, the Green Party, quit the two-party coalition after the government’s budget bill was rejected.
The Green Party said it could not accept a budget “drafted for the first time with the far-right,” reported BBC.
Ms Andersson’s decision to step down came hours after she said earlier that she would not, in case she lost the budget vote.
“I am of the opinion that [the opposition budget] as a whole is something I can live with,” she had said before the budget vote.
However, after the budget vote Ms Andersson told reporters that the Green Party’s decision had forced her to step down.
“A coalition government should resign if a party chooses to leave the government. Despite the fact that the parliamentary situation is unchanged, it needs to be tried again,” she said.
For the budget vote, Ms Andersson had sought support from two smaller parties, the Centre Party and the Left Party.
The budget was defeated after the Centre Party withdrew support, even though Ms Andersson had struck a last-minute deal with the Left Party to secure support for the budget.
By a vote of 154-153 the parliament approved the budget by the opposition conservative Moderates, Christian Democrats and far-right Sweden Democrats.
The approved budget aims at reducing taxes, increasing salaries for the police and increasing expenditure on different sectors of the judiciary.
The Green Party said it was in the party’s best interest to pull support for Ms Andersson after her budget loss.
“For me, it is about respect, but I also do not want to lead a government where there may be grounds to question its legitimacy,” Ms Andersson said after stepping down.
The development followed a historic afternoon when the Swedish parliament voted for Ms Andersson to become the first female leader of the country, a hundred years after Swedish women were given the right to vote.
Ms Andersson who had recently become the head of the majority party, the Social Democrats, received a standing ovation from sections of the parliament after her victory. While Sweden is known for its gender equality, the country had not had a female prime minister prior to this.
She was voted to power by a single vote in the 349 member-Swedish parliament or Riksdag, with 117 members supporting her, 174 members voting against her, 57 members who abstained and one who was absent.
The Swedish Constitution says that prime ministers can be named or govern as long as a majority 175 members are not against them.
Speaker of parliament Andreas Norlen said he will contact Sweden’s eight party leaders “to discuss the situation” and will announce the next move on Thursday, reported Associated Press (AP).
Ms Andersson’s chances of returning to power, however, remain good. The Green Party has promised to support her even though they have quit the government over the budget.
The Left Party has also already said that it will back her.
The Centre Party said that it will abstain, which will amount to supporting Ms Andersson.
The opposition Moderates and Christian Democrats are backed by the Sweden Democrats, but cannot command a majority in parliament.
If Ms Andersson returns as prime minister, it is likely that she will be at the helm of a fragile minority government and would still have to stick to the right-wing budget approved by parliament, BBC reported.
Sweden is scheduled to hold elections next year on 11 September.