Gagne and Mike Richards scored the only goals in the shootout, and the Flyers matched their biggest comeback since Feb. 23, 1988, when they wiped out a 5-1 deficit against Detroit and won 11-6.
Philadelphia had been 0-2 in shootouts this season. The Flyers forced the tiebreaker by pushing four rebound shots past Carolina goalie Michael Leighton in the third. Hartnell scored on putback shots at 1:42 and 7:12.
Eric Staal scored two goals and added an assist for the Hurricanes, who had lost three straight and six of seven before beating Washington 3-1 on Sunday.
Matt Cullen, Sergei Samsonov, and Joni Pitkanen also scored, and Tuomo Ruutu added two assists for Carolina, which earned an overtime win over the Flyers in Philadelphia the day after Thanksgiving. That was the Hurricanes' final victory under former coach Peter Laviolette, who was fired five days later.
Leighton, starting in place of Cam Ward who is day to day with a groin injury, made 32 saves.
Antero Niittymaki stopped 26 shots to earn his fifth win in six starts.
Staal put the Hurricanes ahead just 1:01 in, scoring his 10th goal of the season and his 300th NHL point. Staal had another goal disallowed later in the period when he was called for high-sticking.
Cullen made it 2-0 when his shot from the goal mouth bounced under Niittymaki's armpit and trickled into the net at 2:10 of the second.
After Hartnell got the Flyers to within a goal with a rebound of Carter's shot at 9:17, the Hurricanes broke the game open with three goals in a span of 5:45.
Samsonov put in a rebound at 9:28. Pitkanen scored on a slap shot, with the Hurricanes on a 5-on-3 power play at 12:08, and Staal added his second goal on another power play at 15:13 to give Carolina a 5-1 lead.
It was Staal's 20th career two-goal game.
Philadelphia and Carolina finished their season series by playing their fourth game against each other in 16 days. The Flyers went 3-1-1 against the Hurricanes.
Notes: Richards extended his point streak (5 goals, 4 assists) to six games. ... Carolina RW Justin Williams scored his first point of the season by assisting on Cullen's goal. He played in his fourth game after missing 25 following surgery to repair a torn Achilles' tendon. ... The Hurricanes are 1-1-2 since Paul Maurice replaced Laviolette on Dec. 3.