Travis Konecny had a goal and two assists for Philadelphia (36-20-7), which won its fourth straight game and is 7-3-0 in its past 10.
Carter Hart made 26 saves for Philadelphia, which trails the Washington Capitals by five points for first place in the Metropolitan Division and the Pittsburgh Penguins by one point for second.
"We ended up winning the game, but it wasn't the prettiest game on our end," Hayes said. "We just kind of stick to our system. Tonight, when we had bounces go our way, we took them and put them in the back of the net."
WATCH: [All Sharks vs. Flyers highlights]
The Sharks (26-33-4), who have lost five games in a row, including four straight on the road, played for the first time since trading forward Patrick Marleau to the Penguins on Monday. Aaron Dell made 23 saves.
San Jose forward Logan Couture returned after missing 17 games since fracturing his ankle Jan. 7. He had two shots on goal in 18:05.
"I feel all right," Couture said. "Wish I played a little bit better, but I'm OK. ... I knew my hands weren't going to be great. I figured it's been a rough couple days."
Hayes' line with Konecny and Scott Laughton (two assists) was put together following the trades that brought centers Nate Thompson and Derek Grant to Philadelphia on Monday. That allowed Laughton to shift from center to left wing.
"I think all three of our games complement each other," Hayes said. "[Konecny] is an electric skater, he's easy to play with. [Laughton] brings a lot of grit, hard work to that line, causes a lot of commotion. I try to look for those two guys."
That commotion led to Hayes' first goal, when he and Laughton double-teamed defenseman Brent Burns at center ice and forced a turnover. Hayes scored off a cross-ice pass from Laughton to put the Flyers ahead 2-1 at 3:51 of the second period.