Jason Zucker scored two goals, and Matt Murray made 18 saves for the Penguins (37-20-6), who have been outscored 19-8 during the losing streak.
Zucker scored his second goal to make it 3-2 with 1:21 left and Murray pulled for an extra skater, but Gibson saved the final two shots.
The Penguins outshot the Ducks 10-2 in the first period and Anaheim didn't get its first shot on goal until 13:50.
Heinen scored on the second shot at 14:14 for a 1-0 lead.
Penguins defenseman Zach Trotman gave the puck away in the Pittsburgh zone and Anaheim defenseman Josh Manson took possession before dumping it behind the Penguins net. Kiefer Sherwood tapped a backhand pass out front to Heinen, whose shot deflected off Trotman into the net.
Heinen was one of five players in the Anaheim lineup who were acquired at the NHL Trade Deadline on Monday.
"Manson stepped up and made a good play to get the puck low," Heinen said. "Sherwood made a great little play up front and I got a lucky bounce."
Ryan Getzlaf received a double-minor with 56 seconds left in the first period, and Zucker tipped in a point shot by defenseman Marcus Pettersson during the second minor at 1:16 of the second to tie the score 1-1.
Pittsburgh defenseman Justin Schultz received a double-minor for high-sticking Getzlaf, who scored 34 seconds into the power play for a 2-1 lead at 9:23.
Getzlaf passed the puck diagonally from below the goal line to Sam Steel at the right face-off dot. Murray made a right pad save on Steel's wrist shot, but the rebound came out to Getzlaf, who hit the wide-open net.
Gibson made his best save while the Penguins were shorthanded when he extended his left pad on a shot by Bryan Rust at 16:02 of the second period.
"He made a big [save] there," Penguins forward Sidney Crosby said. "Then we ended up giving up one. Unfortunately, we had a couple go off us tonight and hit a couple posts, and things like that, but yeah, [Gibson] definitely played well."
Brendan Guhle scored from the high slot to make it 3-1 at 17:20.
The puck got behind Murray in the crease and Trotman swept it out to Evgeni Malkin, who missed it as he skated by. The puck continued to Guhle in the high slot, and his slap shot grazed off Trotman.