The Americans will face Japan on Thursday in a rematch of last year's Women's World Cup final, when the Asians prevailed on penalty kicks.
Alex Morgan outleapt Canadian defender Chelsea Stewart at the six and headed in Heather O'Reilly's cross from the right to give the Americans the win 2½ minutes into injury time of the second extra period.
Christine Sinclair scored three times - twice in the second half - to put Canada ahead - the last time in the 73rd, but the Americans equalized each time. Megan Rapinoe scored twice and Abby Wambach converted a penalty in the 80th minute to tie the game 3-3.
It was the 44th victory for the United States in 52 matches against its CONCACAF rival, extending its unbeaten streak to 27 matches since 2001.
"For some reason we like things dramatic. I'm just glad I'm on the same team as Alex Morgan," Wambach said. "This team doesn't give up. This is what we've been working for since losing the Women's World Cup to Japan."
Canada will face France on Thursday for the bronze medal.
Sinclair gave Canada the lead in the 22nd minute. With the United States dominating possession and play early, Marie Eve Nault played a ball into the top of the area to Melissa Tancredi, who laid off a square ball to a streaking Sinclair.
The 29-year-old attacker took two touches and unleashed a right-footed shot past Hope Solo, ending the U.S. goalkeeper's goalless streak at 368 minutes.
The rest of the half was relatively even but the Americans again took the initiative to start the second 45 minutes and equalized when Rapinoe curled a corner to the near post in the 54th.
With Alex Morgan making a run in front and Rachel Buehler behind, confusion in the Canadian defense allowed the ball to bounce between Sinclair and Lauren Sesselmann, and skipped in off the knee of Canadian keeper Erin McLeod.
Sinclair restored the lead in the 68th, freeing herself of U.S. defender Kelley O'Hara in the middle of the area and getting to Tancredi's cross to drive a header inside the left post.
But Rapinoe equalized just under three minutes later, settling a cross-field ball from Lauren Cheyney at the top of the area and rifling a right-footed shot off the inside of the left post.
Sinclair took only another 2½ minutes to put Canada ahead for a third time, getting clear to head in Rhian Wilkinson's corner over the head of Amy LePeilbet standing at the left post. It was her 143rd careeer goal, putting her one ahead of Wambach for second most in women's soccer history -- temporarily.
The United States equalized once more on a penalty kick, set up when McLeod was penalized by Norwegian referee Christina Pedersen for the rarely called infraction of taking too much time to release the ball.
The Americans were awarded an indirect free kick inside the penalty area, and Nault on the right edge of the Canadian wall was whistled for a handball. Wambach converted for the United States, sending the ball off the inside of the left post for her 143rd career goal.