Trailing by two goals with under four minutes to play in regulation, Canada scored twice, including one with 55 seconds to play, before going on to win on Marie-Philip Poulin's goal eight minutes into the sudden-death overtime period.
Switzerland beat Sweden earlier on Thursday to claim bronze.
The Americans, who were clinging to a one-goal lead late in the third period, almost sealed the win when a shot from their end of the ice hit the post of a Canadian net left empty in favor of an extra attacker.
That proved costly as Poulin tied the game moments later, deflating an American team that could almost taste their first Olympic gold medal since 1998.
In contrast to the high-octane ending, the first period was scoreless but things began to heat up in the second.
Canada's Meghan Agosta missed a glorious chance to open the scoring near the midway mark of the second period but her shot from in close was stopped just short of the goal line when U.S. goalie Jessie Vetter got her left pad out at the last second.
American captain Meghan Duggan opened the scoring minutes later when, after a turnover right outside the Canadian zone, she sent a fluttering puck into the top right corner of the net with eight minutes left in the second.
A third period goal from American forward Alex Carpenter, who was parked alone outside the Canadian goal crease when she redirected a perfect Hilary Knight pass into the net, gave the U.S. team a lead that looked safe.
Canada's Brianne Jenner pulled Canada to within one in the game's closing minutes to set up the frenetic finish.
Earlier on Thursday, Switzerland won their first medal in women's ice hockey after rallying from a two-goal deficit to beat Sweden 4-3 in a frenetic bronze medal game.
Trailing 2-0 going into the final period, Switzerland came to life with goals from Sara Benz, Phoebe Stanz, Jessica Lutz and an empty netter from Alina Muller.
"It's an amazing feeling," Muller told reporters. "It's amazing we came back from 2-0 down."
Sweden, the 2006 silver medallists, had looked on course for the win as they controlled the first two periods.
But Switzerland fought back with two goals in the opening six minutes of the last period, first when Benz pounced on a loose puck near the top of the crease and five minutes later when Stanz tallied on a powerplay.
With under seven minutes to play and the game tied, Sweden were unable to clear their zone and the Swiss made them pay as Lutz sent a perfect pass from Lara Stalder flying into the net.
Muller's empty-net goal with 67 seconds to play proved crucial to Switzerland's medal hopes as Sweden managed to get one back in the closing minute of a wild period.
The final buzzer set off a crazy celebration among the Swiss players, who mobbed each other in the corner of the rink. The despondent Swedish team were littered on the ice and their bench staring down at their yellow jerseys.
"It sucks. We have been playing really well through the tournament but we lost all of it in that third period," said Jenni Asserholt, who assisted on Sweden's last-minute goal. "It feels really tough to accept. We just messed up."
After finishing last in their group during the preliminary round, Switzerland beat Russia in the quarter-finals before losing in the semi-finals to Canada.
Since women's ice hockey made its Olympic debut at the 1998 Nagano Games, Canada and the United States have competed for every gold medal except one. The lone exception came in 2006 when Sweden lost to Canada in the final.
Finland and Sweden had been the only countries apart from the two North American ice hockey superpowers to reach an Olympic podium, a trend that put the women's tournament under the microscope in Sochi.
"Hopefully, we can just get better from here," said Stanz. "Women's hockey is going to be taken seriously, especially in Europe."