Joel Farabee had a goal and two assists and Shayne Gostisbehere, Wade Allison and Robert Hagg also scored for the Flyers, who snapped a three-game skid and won for just the sixth time in the last 16.
"I think it happens to every team that sometimes you just don't have the legs, and I think we were just faster and fresher than them," said Jakub Voracek, who had three assists.
Sidney Crosby and Jason Zucker scored for the Penguins, who are tied atop the East Division with Washington. Each has 71 points, but the Capitals have four games left while Pittsburgh has three.
Evgeni Malkin returned to the lineup for Pittsburgh after missing 23 games with a lower body injury. The Penguins didn't miss a beat without the four-time All-Star, winning 16 of the contests during his absence. Malkin had an assist on Crosby's tally.
Alex Lyon made 35 saves for his first victory in his fourth start.
"He really gave us a chance," Flyers coach Alain Vigneault said.
The Flyers were thought to be a Stanley Cup contender at the season's outset, and that didn't change after starting the season with a convincing two-game home sweep of the Penguins. But Philadelphia (23-22-7, 53 points) has been in a free fall since the end of February, was eliminated from the playoffs last Thursday and are just trying to stay about .500 with four games remaining.
The Flyers probably wish they had more games against the Penguins, though. Philadelphia improved to 5-2 against Pittsburgh with one of its best performances of the season.
Asked about his club's performance against the Penguins compared to the rest of the East, Vigneault said, "You don't want to ruin my win, do you? Sort of happy right now. Let's celebrate the win and we'll talk about that later."
The Flyers jumped out to a 3-0 first-period lead for the first time this season.
Hayes' tally 5:58 into the contest to give Philadelphia a rare early advantage. The goal wasn't whistled on the ice as it looked like Casey DeSmith made a remarkable glove save on Hayes' wraparound shot, but replays showed that DeSmith's glove actually was over the goal line and was awarded after an officials' review.
It was the first time in 11 games and just the second time in the last 22 contests that Philadelphia scored first.
"I thought we played with the puck for most of the night, and we weren't chasing the game," said Philadelphia's Scott Laughton, who had an assist.
Gostisbehere's slap shot from the point through traffic on the power play made it 2-0 with just under 5:52 left in the period. And Giroux notched his 15th 1:04 later. Sean Couturier sent the puck behind the net, Konecny tipped it to the slot and Giroux fired it past DeSmith's glove.
Crosby netted his 21st of the season and 47th in 76 career games against the Flyers 2:30 into the third when he tipped Kris Letang's pass over Lyon's left shoulder from the side of the net. Zucker pulled Pittsburgh within 4-2 with 11:36 remaining when he tipped John Marino's shot past Lyon for another power play goal, but Farabee dashed any hopes of a Pittsburgh comeback with his team-leading 17th goal with 8:23 left.
"I just don't think we were on our game," Pittsburgh coach Mike Sullivan said. "I don't think we were skating, I don't think we were playing the game here that has brought us success."
Lyon made a remarkable save with 10 minutes left in the first period to keep the Penguins off the board. Lyon stopped Kasperi Kapanen's long shot, but it knocked the stick out of Lyon's hand. The puck trickled behind Lyon and toward the goal, but he sprawled around and used his hand under his blocker to stop the puck just before it crossed the goal line.
"Kind of one of those you turn around in desperation and just swat it out," Lyon said.
Penguins: DeSmith exited after the second period with a lower body injury and will be evaluated further on Tuesday, Sullivan said. He was replaced by Tristan Jarry. ... D Mike Matheson is listed as week to week after taking a puck to the face in the second period of Saturday's 3-0 win over Washington. ... F Evan Rodrigues (lower body) missed his second straight game. Rodrigues didn't skate on Monday. ... Brandon Tanev (upper body) was out of the lineup for the 13th consecutive game. His return appears near, though, as he skated with full contact on Monday.
The teams close out their season series with the second game of a back-to-back on Tuesday night in Philadelphia.