Sweden beat Brazil 4-3 in a penalty shootout after the sides were goalless following extra time on Tuesday to reach the final of the women's football tournament at the Rio Olympics.
Sweden, whose previous best showing at an Olympics was fourth place in 2004, will now face Germany in the final on Friday.
Lisa Dahlkvist scored the decisive penalty on Sweden's fifth attempt after Andressa, the youngest player on the Brazil squad, saw her penalty saved by Hedvig Lindahl.
Brazil's Cristiane and Sweden's Kosovare Asllani also had their kicks saved.
"It is very emotional," Swedish coach Pia Sundhage, who coached the United States to victory in 2008 and 2012, said.
"I've been in finals in China, in London but then I had a team that everybody expected to do well. If you look at the team we have, it's been a wonderful road. Emotionally I am thrilled. It's hard to believe Sweden will play in the final.
"But we are not satisfied," she added. "We want to win the next game."
The result was a huge letdown for the host nation, who were vastly superior and had the raucous support of a capacity crowd at the Maracana stadium.
Brazil had most of the play throughout as Sweden tried the same smash-and-grab tactics that took them past the U.S. in the quarter-finals.
Brazil had 33 shots at goal, compared to Sweden's six.
"I can only say that I feel frustration," said Brazilian coach Vadao. "Nevertheless I will not apologise to our supporters. We did dominate. We tried to find the best way round, we even tried playing in a more disorganised fashion, we tried everything possible."
Sweden, ranked sixth in the world, will play second-ranked Germany at the Maracana on Friday after they enjoyed a 2-0 win over Canada on Tuesday.
Melanie Behringer, with her fifth goal of the tournament, scored after 21 minutes to put Germany ahead and Sara Daebritz added the second goal 14 minutes into the second half.