FARO, Portugal (AP) — Aya Miyama scored a last-minute penalty on Monday as Japan beat Sweden 2-1 to advance to the Algarve Cup final.

Sweden looked in control of the final-deciding match after Linda Sembrant put the Scandinavians on course for the final with her 42nd-minute opener at the Algarve Stadium.

But the world champions began its fightback soon after the break when Yuki Ogimi jumped on Jessica Samuelsson's poor back pass to beat goalkeeper Carola Soberg alone on the break.

Sweden, which beat the United States to sit top of the group coming into the match, was still in control knowing a draw would be enough to progress but then Sweden defender Wind Sembrant was judged to have handled inside the area to set up Miyama's 89th-minute penalty winner.

The World Cup winner topped Group B with seven points - one ahead of Sweden, and face European champions Germany in Wednesday's final.

"It feels pretty hard right now and I'm really disappointed," Sweden coach Pia Sundhage said on the Swedish federation's website. "We were close to the final."

Only the winner of each group advanced to the final, with Germany making it three wins to close Group A play on Monday with a 3-1 victory against Norway in a rematch of last year's European Championship final.

"The Japanese have a very strong team, which is really fun. For the viewers it is certainly an exciting game," Germany manager Doris Fitschen said.

Iceland beat China 1-0 to set up a contest with Sweden in the third-place game.

Elsewhere, Denmark held on for a 5-3 victory over the U.S., as the American women finished last in Group B with one point.

The Danes led 3-0 by the break before the Americans cut the lead to 4-3 through Megan Rapinoe in the 68th.

But Karoline Nielsen sealed it on the counter in stoppage time as the Olympic champions allowed five goals in a game for the first time in history.

The U.S. also lost back-to-back games for the first time since the 2001 Algarve Cup after seeing a 43-game unbeaten run ended in a defeat to Sweden on Friday.

"Tactically we knew how to play them but we didn't do it well in the first half. We let Denmark dictate the game and they were very potent on the counter," U.S. coach Tom Sermanni said. "In the second half we got ourselves back in the game. Again, we had several chances around the penalty area, we hit the post, and at the moment we just can't seem to put the chances away.

"It's been a strange tournament."