Philadelphia won its second in a row to open a two-point lead over Pittsburgh in the race for the No. 4 seed in the Eastern Conference and home-ice advantage in the first round.
Martin Biron made 27 saves, and Darroll Powe added an empty-net goal that Hartnell assisted on for the Flyers, who have three games in hand on the Penguins.
Kris Letang scored for Pittsburgh, which hadn't lost since Feb. 22 at Washington, had been 8-0-2 in its past 10 and lost in regulation for only the second time in 17 games under interim coach Dan Bylsma.
Gagne's 29th goal came while on the power play 5:19 into the contest, when he fired home a loose puck from the left faceoff circle.
The Flyers made it 2-0 with another power play goal 2:54 into the second. Hartnell was credited with his 27th of the season when Jeff Carter's shot from the right circle grazed off Penguins defenseman Mark Eaton and Hartnell into the net behind Pittsburgh goalie Marc-Andre Fleury.
Although the play was reviewed, it was clear Hartnell did not display any distinct kicking motion to direct the puck into the net.
The Penguins lead the league in victories when trailing after two periods (11), but a possible comeback was thwarted partially by Sergei Gonchar's double-minor for roughing after time had expired at the end of the second period.
Pittsburgh killed the Flyers' four-minute power play at the start of the third but only managed seven shots in the period. The Penguins' goal came midway through the period when Letang, a defenseman with a penchant for pinching in on a play, scored his eighth while on the power play off assists from Crosby and Malkin — the league's No. 2 and No. 1 scorers.
Crosby extended his personal point streak to 13 games with his NHL-high 32nd power play assist. Malkin's point was his eighth in his past three and 105th of the season.
The Penguins were 8-1-1 in their previous 10 home games and had won five in a row against the Flyers at Mellon Arena — eight straight if you count last season's Eastern Conference final.
If the postseason ended today, the two teams would meet in the first round.
Notes: Neither Crosby nor Malkin recorded a shot on goal. ... The Penguins won the season series 4-2. ... Gagne has at least a point in nine of his past 10 games. ... Pittsburgh is 3-1-1 on its franchise-record eight-game homestand. ... The Penguins fell to 3-5-2 this season while wearing their blue throwback uniforms and 4-8-2 in afternoon games.