Auston Matthews scored twice late in the third period as the Maple Leafs rallied from a three-goal deficit and held on to beat the Philadelphia Flyers 7-6 Friday night.
"It was pretty crazy," Matthews said. "We showed a lot of resilience."
Jake Muzzin had two goals and an assist, and Patrick Marleau, Zach Hyman and Martin Marincin also scored to for the Maple Leafs, who had five consecutive goals to take the lead after trailing 5-2. Toronto snapped a two-game skid and pulled two points behind Boston for second place in the Atlantic Division.
"We'd like to do it in a different manner," Muzzin said. "But a win's a win."
William Nylander, Nazem Kadri, Nikita Zaitsev and Ron Hainsey each had two assists for the Maple Leafs, and Frederik Anderson finished with 23 saves.
Matthews got the tiebreaking goal with 5 minutes left, taking a one-handed pass from Nylander in front and burying it past Elliott. He then added his 34th of the season with 2:39 remaining off a rebound on a rush to put the Maple Leafs up 7-5.
"The guys did a heck of a job for Freddie," Maple Leafs coach Mike Babcock said. "Freddie's done that for us a bunch. That's just payback."
James van Riemsdyk got his third of the night for his fourth career hat trick on a tip with 1:14 left for his 24th to pull the Flyers within one. However, Toronto held on as Andersen recovered from some questionable moments to rob Shayne Gostisbehere in the closing seconds.
"The guys did a hell of a job," said Andersen, who was pulled in consecutive losses for the first time in his career earlier this week. "It seems like everything's going against me. ... You've got to find a way to fight through it."
Gostisbehere and Radko Gudas each had a goal and an assist, and Jakub Voracek also scored for the Flyers. Claude Giroux had three assists, Nolan Patrick and Sean Couturier each had two and Brian Elliott had 44 saves. Philadelphia has lost two straight after a 6-1-1 stretch.
"We know what kind of team they are," van Riemsdyk said. "They can score at will. They're never out of a game."
Coming off consecutive brutal home-ice performances -- Monday's 6-2 loss to Tampa Bay Lightning and Wednesday's 5-4 loss to Chicago Blackhawks, when they trailed 5-0 late in the second period before a late rally -- the Leafs fell behind 5-2 on Friday before two goals from Muzzin set up Marincin's tying score early in the third.
Marincin, who hadn't scored since Nov. 11, 2016, fired a shot from the point that went off the glove of Flyers defenseman Robert Hagg and in past Elliott at 2:55.
Andersen nearly bobbled the puck into his own net later in the period on a clearing attempt during a Maple Leafs power play, but managed to recover in time.
"I'd love to handle it better and get out of it quicker," Andersen said of how he's handling this rough stretch. "Just trying to work my way out of it."
Toronto nearly went ahead with under nine minutes to go, but Elliott stopped Andreas Johnsson on the doorstep.
Tied 1-1 after the first, the Flyers went ahead at 1:15 of the second when van Riemsdyk tipped his 22nd past Andersen. The forward, who spent six seasons in Toronto before returning to the team that drafted him as a free agent last summer, made it 3-1 when Giroux threw a puck in front that van Riemsdyk got a stick to before it dribbled through Andersen at 8:26.
Hyman, who returned to the lineup after a one-game absence because of the flu, scored his 17th on a slick setup by Mitch Marner just 61 seconds later to get Toronto back within one, but Gudas restored the Flyers' two-goal lead with his third of the campaign and first in 37 games.
Gostisbehere then made it 5-2 less than a minute later when he swept home his seventh after a scramble in front.
The Flyers got on the board first as Voracek, back after missing two games due to a suspension for a hit on Islanders defenseman Johnny Boychuk last Saturday, scored on a one-timer off Patrick's faceoff for his 19th with 7:38 left in the first.
Toronto tied it at with 2:15 left in the period on the power play when Nylander's shot went off Marleau for his 15th, and first in eight games.
The Maple Leafs wore their throwback green and white Toronto St. Patricks jerseys. The Maple Leafs were known as the St. Patricks from 1919 until 1927 when the team was bought by Conn Smythe, who changed the name. Toronto will also wear green and white on Saturday at Ottawa. .,, Voracek has 12 points in his last six games (three goals, nine assists). ... The Flyers dressed 11 forwards and seven defensemen with winger Ryan Hartman out with an illness. ... Hyman returned to the lineup, but Toronto was still minus F Kasperi Kapanen (concussion), D Jake Gardiner (back) and D Travis Dermott (shoulder).
Flyers: At Pittsburgh on Sunday.
Maple Leafs: At Ottawa on Saturday night.
More AP NHL: www.apnews.com/NHL and www.twitter.com/AP-Sports
Matthews' two late goals lift Maple Leafs
Auston Matthews' first goal breaks a 5-5 tie, then scores what would be the game winner in Toronto's 7-6 win against Philadelphia.