Canada ended a 22-year losing streak against Germany on Tuesday with Melissa Tancredi scoring both goals in a 2-1 win in Olympic women's soccer action.
Canada had been outscored 38-13 in losing all 12 previous meetings with second-ranked Germany, a perennial contender which won the 2003 and 2007 World Cups, dating back to July 1994.
The Canadian men have never beaten Germany, losing all three times they have met.
The historic win means Canada, which had already booked its ticket into the knockout rounds, finishes atop Group F after its third victory in as many games. The 10th-ranked Canadian women will play the runner-up in Group G in Friday's quarter-final in Sao Paulo.
That could mean a date with third-ranked France, depending how later games Tuesday went.
Germany finished second in the pool on a tiebreaker over Australia with both teams at 1-1-1 after the Australians beat Zimbabwe 6-1.
The Germans will play the Group E runner-up, one of No. 6 Brazil, No. 8 Sweden and No. 12 China, in Salvador while the Aussies await other results to decide their fate.
The top two teams in each of the three groups and two best third-place finishers advance to the knockout rounds. Matches later Tuesday decided the order of finish in the other groups.
Germany and Canada could meet again in the semifinals.
Melanie Behringer scored from the penalty spot in the 13th minute for Germany at a sparsely filled Mane Garrincha Stadium. Tancredi replied with two beauties, in the 26th and 60th minutes.
Germany came on strong in the dying minutes. Goalkeeper Stephanie Labbe made a diving save off Anja Mitta to preserve the win before Josee Belanger made a goal-line clearance in stoppage time.
The Germans had more of the ball but failed to turn their possession advantage into scoring chances.
With his team playing its third game in seven days, coach John Herdman made six changes to his starting lineup with captain Christine Sinclair and Diana Matheson both rested. One was enforced with defender Kadeisha Buchanan serving a one-game ban for yellow card accumulation.
Sabrina D'Angelo, Ashley Lawrence and Janine Beckie also started on the bench with Labbe, Allysha Chapman, Shelina Zadorsky, Deanne Rose, Rhian Wilkinson and Desiree Scott coming into the lineup.
That meant Canada's bench had 520 caps and 203 goals, not counting the suspended Buchanan.
Tancredi, winning her 123rd cap, served as captain.
Germany made five changes to its lineup.
The Germans had the best of the early going and went ahead in the 13th minute after Chapman took down Mandy Islacker and North Korean referee Ri Hyang pointed to the penalty spot. Behringer had no problem beating Labbe.
Tancredi tied it up in the 26th minute after a German turnover with Scott doing the dirty work. Tancredi then made no mistake, hammering a left-footed shot through two defenders from the edge of the penalty box that beat Almuth Schult in the corner.
A clumsy challenge by Belanger in the 35th minute produced a German free kick just outside the penalty box. But Behringer's delivery was just high.
The Germans had 69 per cent possession in the first half and eight corners to Canada's one. Germany also outshot Canada 10-4 but the Canadians led 3-1 in shots on target.
Lawrence replaced Jessie Fleming at halftime. Matheson and Nichelle Prince came on later in the game.
Mittag came close early in the second half but her stab at a cross went just wide.
Tancredi's power paid off in the 60th minute when she beat two defenders in the air to head in a long-range Rebecca Quinn free kick. It was her 27th goal for Canada and seventh at the Olympics.
Canada came into the game with six points after beating Australia 2-0 and Zimbabwe 3-1. Germany had four after defeating Zimbabwe 6-1 and tying Australia 2-2.