Those three straight knockouts by the Red Sox last week in Boston became more of a distant memory Friday night, as the Yankees opened another four-game series against their rivals with a 4-2 win in front of a sellout crowd in The Bronx.

It was the Yankees’ third win in four games and sent the Red Sox to a season-high fifth straight defeat.

James Paxton recovered from another rough first inning to deliver a solid outing, and the Yankees used a grand slam from Gleyber Torres — also in the first — to open a 7½-game lead in the AL East over second-place Tampa Bay, which was idle, and move 11½ games ahead of Boston.

“I’m not surprised,’’ Aaron Boone said of his team’s ability to bounce back. “No matter what’s happened, they’re not really that affected by a bad night or a bad couple days or, for that matter, a great couple of nights. They expect to go out and win. There’s a lot of comfort in that, when you come to the field knowing you can really play.”

The victory began a stretch of 19 games in 17 days for the Yankees, who are in need of more depth from their starters. Paxton (6-6) was much-improved over his previous two starts, when he gave up 14 runs (11 earned) over a combined 7¹/₃ innings. His previous outing came in Boston, when the Red Sox hit four homers off him.

“I didn’t make as many mistakes,’’ Paxton said of Friday’s start. “And the ones I did make, they didn’t put over the fence.”

The night wasn’t all good for Paxton, whose first-inning struggles continued when he allowed a two-out, two-run homer to J.D. Martinez. Paxton has given up a homer in the first inning of each of his past four starts and his ERA in opening frames this season is 11.36.

But the Yankees didn’t trail for long.

DJ LeMahieu, back after missing four games with a tight groin, led off the bottom of the first against left-hander Eduardo Rodriguez (13-5) with a single, and Aaron Judge and Edwin Encarnacion walked to load the bases with no one out.

Aaron Hicks fouled out before Torres lined a homer into the left-field seats to give the Yankees a two-run lead. The shot snapped a 3-for-22 slide for Torres, who filled in at shortstop for Didi Gregorius, who is nursing a strained finger in his left hand.

Neither team scored after the first, as both Paxton and Rodriguez settled in.

Paxton retired eight straight following Martinez’s home run and eight of the last nine he faced before being pulled after the sixth. He allowed just two runs and a pair of hits in the 100-pitch performance.

The Yankees couldn’t get to Rodriguez again, but it didn’t matter, as Tommy Kahnle tossed a scoreless seventh, Zack Britton did the same in the eighth and Aroldis Chapman finished the job with an easy ninth.

It was a welcome change for Chapman, who had allowed nine runs (eight earned) in 8²/₃ innings in his previous nine outings. Opposing batters had hit him well, with nine hits in that span, but he also had struggled with his control, walking eight batters.

“That was good to see,’’ Boone said of Chapman’s outing. “He’s been a little up and down lately with his command. Hopefully this is something that gets him rolling again.”

The win continued a turnaround for both teams, as the Red Sox seemed to be surging up the division last Saturday and the Yankees’ rotation was in the midst of a horrific week.

“It was more a bump in the road,’’ Britton said. “It’s definitely frustrating when you go into Fenway and don’t perform. We needed to perform better and this has been a good step in the right direction.’’

The Yankees’ fortunes began to turn with Sunday night’s win. Then, while they split two games at the Stadium against the Diamondbacks, the Red Sox were swept at home by the Rays and weren’t factors at the trade deadline.

“Look, we’re just trying to rack up wins,’’ Boone said. “Anytime you can rack up a win, especially against a division opponent that is as capable as the Red Sox are, you enjoy those a little more.”