She said she would hand in her resignation notice on Thursday after it emerged that the opposition blue bloc consisting of the Moderate Party, the Christian Democrats, the Liberal Party and the Sweden Democrats, had won 176 of the 349 seats in parliament.
Meanwhile Andersson's red bloc, consisting of her Social Democratic Party, the Left Party, the Green Party, and the Centre Party, won 173 seats. She will now lead a transitional government until the new one has been installed.
"We have made the largest increase in voter support in 20 years and we are not only Sweden's largest party -- we are also the largest party in northern Europe. I am proud and grateful that almost two million Swedes chose to vote for us," Andersson said.
Despite the blue bloc ending up with three seats more than the red bloc, some analysts consider the blue bloc as fragile, since the Liberal Party has vowed not to tolerate a government that includes the Sweden Democrats. There are also fundamental differences between the Sweden Democrats and the other parties in the bloc when it comes to issues such as the unemployment insurance and other economic issues.
Also, during the election campaign Ulf Kristersson, leader of the Moderate Party -- which after decades lost its position as Sweden's second largest party to the far-right Sweden Democrats -- repeatedly said that the Sweden Democrats would not be included in his government should his bloc be victorious.
"It is now clear that the Sweden Democrats is now Sweden's second largest party and I know that this worries many Swedes," Andersson said, adding that political polarization had "become far too great also in Sweden." She also mentioned that she was prepared to explore another solution should Kristersson's efforts to form a government fail.
"If it turns out that Ulf Kristersson's intended basis does not hold together, then of course my door is open," Andersson said. "We Social Democrats are ready to cooperate with anyone who wants to be part of the solution to the problems that Sweden is facing."
Andersson took over from Stefan Lofven as both leader of the Social Democrats and the country's prime minister last November, following a period of political turbulence. She therefore became Sweden's first female prime minister.
On NATO's 69 anniversary, let's take a look at the organization's "humanitarian interventions" over history. pic.twitter.com/aev5cLI43H