Gagne scored his second goal of the game on a power play 27 seconds into overtime as the Flyers snapped a team-record, 13-game home losing streak with a 4-3 victory over the St. Louis Blues on Saturday night.
The Flyers hadn't won in Philadelphia since the day after the U.S. Thanksgiving.
"We were talking about something to get our luck turned around and we got a break," Gagne said. "We got a power play in overtime and that might be the luck we were looking for."
Gagne, who tied the game at 3 with a deflection of Derian Hatcher's shot with 4:55 left in regulation, scored the winner from the right side of the net by redirecting Mike Knuble's shot.
The Flyers were skating with the man advantage after Petr Cajanek was penalized for holding with three seconds left in regulation.
"When you get hot, it's all about timing," Gagne said.
Jeff Carter and Mike Richards also scored for the Flyers, who had not won at home since Nov. 24 when they beat Columbus in former Flyers coach Ken Hitchcock's debut with the Blue Jackets.
Peter Forsberg, who assisted on both of Gagne's goals, said the Flyers' first home win in more than 11 weeks felt great.
"I think everybody in the building felt the same way," the Flyers captain said. "We have been close so many times. We deserve to win. We played pretty hard. It's just fun to win a game after losing so many."
Philadelphia has won an NHL-low four home games this season (4-15-7).
Lee Stempniak, Keith Tkachuk, and David Backes scored for the Blues, 5-2-1 in their last eight road games.
"I treat the Flyers like the Detroit Red Wings right now because they're playing desperate," St. Louis coach Andy Murray said. "They've been playing hard so we knew we'd be in for a battle.
"They got guys battling for jobs."
Backes redirected a centring pass from Radek Dvorak to break a 2-2 tie at 6:33 of the third period with his second goal of the season.
Philadelphia goaltender Michael Leighton, making his first NHL start since March 23, 2004, when he was with Chicago, stopped 25 shots. He was claimed on waivers from Nashville on Jan. 11 and came up with a solid performance.
"I thought he looked pretty composed for not playing in a while," Flyers coach John Stevens said. "He was confident when we told him he was playing and he felt good."
Curtis Sanford, who made 22 saves for the Blues, said Gagne's winning shot was the last thing he was expecting.
"I was covering the short side looking for the pass and the puck got tangled up in (Knuble's) feet," he said. "He kicked it out to the guy beside the net, and Gagne tipped it in."
Each team scored twice in the second period. With St. Louis skating with a two-man advantage, Stempniak put the Blues ahead at 1:45 of the period by poking in a rebound of Dennis Wideman's shot.
Carter pulled the Flyers even at 5:13 with a snap shot from the right circle that sailed high over Sanford's outstretched glove.
Richards made it 2-1 at 9:53 when he hammered in a rebound of his own shot.
Tkachuk tied it again with 2:54 left in the period when he banked a shot off the left skate of Flyers defenceman Denis Gauthier.
Notes: St. Louis played its second of only four road games scheduled in February. ... The Blues are 4-2 against Eastern Conference teams this season. ... Carter grazed the post during a power play late in the first period. ... The Flyers have won eight of nine against the Blues. ... It was Backes' first goal in 21 games.