BUFFALO, N.Y. — Canadian goalie Carter Hart spent the weeks leading up to the world junior hockey championship insisting he wasn’t focused on losing last year’s title game in a shootout to the United States.

On Friday night, with a shiny gold-medal hanging around his neck, Hart can put fully put the past behind following a 35-save performance in a thrilling 3-1 victory over Sweden.

“It’s one of the best days of my life right now, and it’s definitely better than last year’s tournament,” Hart said of the 5-4 shootout loss in which Canada squandered a 4-2 third-period lead. “It’s hard to describe how it feels right now but it’s something I’ll never forget.”

Tell that to Tyler Steenbergen. The least-used forward on Canada’s roster this tournament provided the climactic moment by re-directing in Connor Timmins’ pass to break a tie with 1:40 left.

With the mostly red-and-white, Maple Leaf-flag-waving crowd still celebrating, Alex Formenton then sealed Canada’s 17th gold medal victory by scoring into an empty net 26 seconds later.

“I just blacked out when it happened,” Steenbergen said. “I’m at a loss for words. And to win it for all the crowd that came out for us was pretty special.”

Drake Batherson set up the decisive goal by forcing a turnover behind the Sweden net. From the left corner, Batherson fed Timmins just inside the blue line. Timmins then fed a hard pass into the left circle, hitting Steenbergen, who swept the puck behind goalie Filip Gustavsson, who was set at top of this crease.

Canadian captain Dillon Dube also scored in a game Canada never trailed.

The frustration and disappointment was palpable for Sweden, which dropped to 1-6 when playing in the championship game, including 0-4 when facing Canada.

Swedish captain Lias Andersson was so upset that upon being awarded his silver medal, he immediately skated away and threw it into the stands.

“I didn’t want it. The guy in the stands wanted it more than me,” Andersson said.

It’s not as if he lacks silver medals, Andersson added, by noting he has another one at home from losing the Under-18 championship.

The United States came away with some hardware.

Kieffer Bellows broke Jeremy Roenick’s U.S. single-tournament record by scoring ninth goal in the Americans’ 9-3 win over the Czech Republic in the bronze-medal game earlier in the day. Trent Frederic scored four times and the earned a medal for a third straight year to mark the nation’s longest streak in tournament history. The U.S. also finished third in 2016, while upping its medal total to 11 (four gold, one silver and six bronze). Two of the third-place finishes coming in Buffalo, where the tournament was also held in 2010-11.

Tim Soderlund scored for the Swedes, who settled for winning their 11th silver medal.

Gustavsson stopped 25 shots.

It was essentially a home game for Canada, with much of the arena filled with fans who flocked across the border from southern Ontario. A rendition of “O Canada” could be heard being sung from the arena foyer 45 minutes before puck drop.

The Swedes were booed each time they took to the ice to open a period, and “Go, Canada Go!” chants were prevalent.

Canada struck first on Dube’s goal 1:49 into the second period, when he was set up by a perfect pass from Jordan Kyrou.

It marked the first time in seven tournament games in which the Swedes trailed. They rolled through the preliminary round by going 4-0 and out-scoring their opponents by a combined 20-7 margin.

The Swedes responded by capitalizing on their speed and play-making skills by scoring their tournament-leading fourth short-handed goal and third in two games.

With Lias Andersson serving an interference penalty, Linus Lindstrom burst up the ice and gained the Canadian zone and cut toward the middle to draw the defenseman toward him. Lindstrom then dropped a no-look pass to Soderlund, who was at full speed along the right wing. Cutting to the net alone, Soderlund banked a shot in off the near post.

Hart was otherwise perfect.

His best save came midway through the second when he kicked out his left pad to foil Fabian Zetterlund’s shot from the slot.

Canada’s newcomers and returning players knew what the win meant to their goalie, and mobbed Hart in the corner of the Canada’s end as the final horn sounded.

“For him, specifically, I think it was the biggest redemption tournament I’ve ever seen for a goaltender,” defenseman Cale Makar said. “He’s just a stud on the back end and we knew we could rely on him in any situation. He brought it tonight and thanks for that.”

Coach Dominique Ducharme grew emotional following the game. He was a Canadian assistant coach at the 2016 world junior tournament in Finland when his father died.

“I wanted to bring him back gold. We didn’t make it that time,” Ducharme said of Canada’s sixth-place finish in 2016. “I thought last year in Montreal it would be a good time to close that chapter. It was really close. To do it here tonight, I can say now that mission is accomplished.”

United States 9, Czech Republic 3

 Trent Frederic scored four times in leading the United States to a 9-3 victory against the Czech Republic in the bronze-medal game.

Kieffer Bellows scored twice, including once on a penalty shot, and added an assist. Joey Anderson and Patrick Harper had a goal and assist each, and Ryan Poehling also scored.