It took 20 minutes for the Flyers’ new lines to find some chemistry, but they regrouped and increased their winning streak to four straight on Tuesday.

Kevin Hayes had two goals and an assist and Carter Hart continued his superb play at the Wells Fargo Center, carrying the opportunistic Flyers past San Jose, 4-2.

The win moved the Flyers to within one point of second-place Pittsburgh in the Metropolitan Division. The Penguins have two games in hand.

Flyers coach Alain Vigneault climbed into a tie with Pat Quinn for the 10th-most wins (684) in NHL history.

Hart made 26 saves and is now 17-2-2 at home. In games at the Wells Fargo Center this season, he took a 1.64 GAA and .942 save percentage into the night.

“I think tonight, when we had some bounces go our way, we took them and put them in the back of the net,” Hayes said.

Earlier in the day, Vigneault said he moved Scott Laughton -- who had been the third-line center -- to Hayes’ line because he liked the chemistry the two forwards displayed in their 21 games together earlier in the season. So Laughton was moved to left wing on the second line, and newcomer Derek Grant played center on the third line.

The move worked perfectly. Hayes’ line, with Laughton (two assists) and Travis Konecny (goal, two assists), had three of the Flyers’ goals and combined for eight points. Hayes had his 20th and 21st goals.

It was just the Flyers’ second win in their last 12 home games against the Sharks, and it avenged a 6-1 loss in San Jose on Dec. 28.

“They kind of kicked our [butt] the last time,” said Hart, who was the loser in that game, “and it was time for us to return the favor.”

Hayes gave the Flyers a 4-1 lead with 16 minutes, 17 seconds left in the third, and Noah Gregor answered for the Sharks with 11:42 to go. But San Jose, which suffered its fifth straight loss, would not get any closer.

The Flyers allowed just three shots over the last 28 minutes

“The second half of the game, we played the way we wanted to play,” said Vigneault, whose team is 22-5-4 at the Wells Fargo Center -- the most home wins it has had at this point in the season since 1986-87.

After a sluggish first period, the Flyers built a 3-1 lead on second-period goals by Hayes and Konecny (22nd).

“We had a good conversation at the first intermission and came out better,” Konecny said. “The message was received."

Hayes, who now has two more goals than he scored last season, finished off a three-on-two by converting a pass from Laughton with 16:09 left in the second.

After San Jose pinned the Flyers in their own end for a while, Hayes broke out and fed Konecny on a two-on-one rush. Konecny put it between goalie Aaron Dell’s legs to make it 3-1 with 10:19 remaining in the second.

The line changes seemed to affect the Flyers in a 1-1 first period in which they were outshot, 15-8 -- 15-2 after they had the game’s first six shots.

A pair of trades Monday brought centers Nate Thompson and Grant to the Flyers and caused Vigneault to change three of his lines, and they all looked out of sync in the opening 20 minutes.

The only line that looked sharp was the one that stayed intact: Sean Couturier centering Claude Giroux and Jake Voracek.

The Flyers got off to a quick start, thanks to Nic Aube-Kubel’s early power-play goal. Aube-Kubel, playing on the second power-play unit as he replaced Joel Farabee (demoted to Phantoms), gave them a 1-0 lead as he took a pass from James van Riemsdyk and scored from the slot after just 92 seconds.

But the Sharks gradually took over the period, getting the equalizer as Joel Kellman scored on a rebound with 13:30 left in the first.

Hart was superb in the first 20 minutes. He made 14 stops, including a save on Logan Couture on a two-on-one. He also stopped point-blank chances by Stefan Noesen and Kevin Labanc.

“Hartsy made some big saves early in the game that kept us in it,” Hayes said.

Couture, the Sharks’ top-line center, returned to the lineup after missing 17 games with a broken ankle.

With just under a minute left in the first period, Laughton’s shot hit the crossbar and post but failed to go into the net, and the teams remained deadlocked heading into the second period.

Hayes’ line took over the rest of the way. The Flyers now have a 17-0-1 record in games in which Hayes scores a goal. Or two.