Defending champions New Zealand underlined their status as women's rugby powerhouse when they won Olympic sevens gold on Tuesday, but they were pushed all the way to their 19-12 win by a Canadian team who had stunned Australia in the semifinals.
The outsiders, thrashed 33-7 by New Zealand in their pool meeting, threatened an even bigger upset when they led 12-7 at the break in a hugely entertaining final, but the holders dominated the second half and were worthy winners.
The United States earlier won the country's first medal in women's or men's Olympic sevens with a last-play score to stun Australia 14-12 and take the bronze.
On a hot, humid evening in front of another 67,000 Stade de France crowd, New Zealand started well and led after Risi Pouri-Lane threw an outrageous halfway line dummy then ran clear.
They then had Portia Woodman-Wickliffe yellow-carded and, as so often happens in sevens, Canada took advantage of the space to send Chloe Daniels over to make it 7-7.
Amazingly they then went ahead when Alysha Corrigan stole the ball and made it over the line to put Canada 12-7 ahead at the break.
New Zealand had barely been tested in their march to the final but they knew they were in a game this time.
They hit back quickly through their main strike weapon, Michaela Blyde, who sidestepped two defenders to restore the lead with her 10th try of the Games.
Canada, who were the Stade's villains when they upset France in the quarter-finals, had the crowd behind them on Tuesday and continued to press.
But New Zealand kept their shape and discipline in defence and a break by captain Sarah Hirini sent her teammates pouring forward and a neat exchange released Stacey Waaka to settle it.
"It's pretty special. I'm proud of the team. I'm proud of the team around us, the people at home who have supported every single one of us, and helped us get to this moment. It takes a whole tribe," said captain Pouri-Lane.
"We've got some great players retiring after this tournament and we owe them such a lot. We've learned such a lot from them, and been empowered by them. But not just us, all around the world."
Australia, this season's grand final champions and 2016 Olympic gold medallists, had looked set for their expected place in the final as they led the U.S. 12-0.
Almost the entire second half was played in the U.S. half and Maddison Levi's second try, taking her record Games tally to 14, looked to have sealed it.
However, the U.S. then struck from nowhere as Sedrick broke a tackle in front of her own posts and raced clear to level it at 12-12. She then slotted the conversion for a famous victory.
The night ended with arguably the happiest podium in the entire Olympics. New Zealand delivered a crowd-pleasing Haka after occupying the top step, the only place that would have left them satisfied.
Canada, who won bronze in Rio but managed only ninth in Tokyo, were delighted with their best-ever finish having claimed upset wins over France and Australia that will live with them forever.
The U.S. were also all smiles, reaching the semis for the first time then going one better to claim a medal.
It was a fitting end to a wonderful tournament, lifted initially by France's emotional men's victory but carried along by a host of great matches in front of six successive Stade de France capacity crowds.