Brazil's hopes of a first Olympic women's football gold came to an end at the semi-final stage with a 4-3 penalty shootout defeat by Sweden.
The Swedes will play Germany, who beat Canada 2-0, at the Maracana on Friday.
Brazil went closest to breaking the deadlock in second-half stoppage time but Formiga's header was saved by keeper Helvig Lindahl.
Both teams had a penalty saved before Lindahl blocked Andressa's effort and Lisa Dahlkvist scored the winner.
"They managed to neutralise us and work defensively," said Brazil coach Vadao. "They wanted to win the match 1-0. If not, they were ready to take it to penalties.
"It's not for me to criticise an opponent as their strategy worked and they had good results in both matches against us and the USA."
Later, Germany ensured it was an all-European final as goals from Melanie Behringer and Sara Dabritz earned them victory over London 2012 bronze medallists Canada.
Behringer opened the scoring from the penalty spot after Kadeisha Buchanan fouled Alex Popp in the area.
Dabritz added the second goal after the break when she fired in from the edge of the area.
Take part in our new Premier League Predictor game, which allows you to create leagues with friends.
Subscribe to the BBC Sport newsletter to get our pick of news, features and video sent to your inbox.