The Yankees' Giancarlo Stanton, right, leaps to celebrate with Josh...

The Yankees' Giancarlo Stanton, right, leaps to celebrate with Josh Donaldson after Donaldson hit a grand slam, on which Gleyber Torres, left, and Joey Gallo scored, during the third inning against the Red Sox at Fenway Park on Thursday in Boston. Credit: AP/Mary Schwalm

BOSTON — Gerrit Cole has never pitched particularly well at Fenway Park, a trend that continued Thursday night.

But with Josh Donaldson and Aaron Hicks hitting back-to-back homers in the third inning — Donaldson’s blast was his team’s third grand slam in two days — and Wandy Peralta, Michael King and Clay Holmes picking up the slack after Cole, the Yankees edged the Red Sox, 6-5, in front of 36,876 at Fenway Park.

“They just do a great job night in and night out,” Donaldson said of the bullpen. “They’re special down there. It’s one of our big strengths as a team.”

A  60-23 team with a 14 1⁄2-game lead over the second-place Rays in the AL East (they're 15 games ahead of the Red Sox and Blue Jays).

Cole, 1-3 with a 5.06 ERA in six career starts at this venerable ballpark — including last October’s 6-2 loss in the American League wild-card game, when he failed to get out of the third inning — allowed a two-run homer by Rafael Devers in the third that brought the Red Sox within 5-2 and a three-run shot to center by Devers in the fifth that made it 6-5. Devers, who homered off Cole in the season opener at the Stadium, has six career homers in 29 plate appearances against Cole.

“I’m open for suggestions,” Cole, who actually threw the ball very well otherwise, said with a weary smile of adjustments he needs to make when facing Devers. “It’s pretty wild. There just hasn’t been a mishit. Like, roll over one time, line out one time. You’re supposed to fail seven out of 10 times in this gig. I don’t know what the deal is. We’ll just have to keep at it, man. Keep it at . . . but it didn’t beat us.”

Cole allowed five runs, five hits and three walks in six innings in which he struck out seven. Because of the Yankees’ early offense, the work of his bullpen and a poor defensive play by the Red Sox on an infield pop-up that allowed what proved to be the winning run to score, he improved to 8-2 with a 3.26 ERA.

Hicks — who gave the Yankees their third set of back-to-back homers in two games when he followed Donaldson’s 429-foot grand slam with a home run on the next pitch — tripled off the rightfield wall with two outs in the fifth inning as the ball ricocheted past Jackie Bradley Jr.

Jose Trevino then popped to first. Franchy Cordero didn’t have to come in particularly far but, after moving in a few steps, he seemed to lose the ball, overran it, reached back and completely missed it. Trevino, running hard, made it to second with what was scored an RBI double, then changed to an error and then changed back to an RBI double.

That made it 6-2 and allowed the Yankees to withstand Devers’ second homer, a 425-foot shot to center that was his 19th of the season. His first homer traveled 434 feet.

Peralta struck out two in 1 1⁄3 innings (and retired Devers on a hard grounder to third). King walked one and fanned one in two-thirds of an inning and Holmes moved to 16-for-17 in save chances with a perfect ninth.

“They were pretty good tonight,” Aaron Boone said of his bullpen for seemingly the 40th or 50th time this season.

Boston rookie righthander Josh Winckowski, who entered the night 3-2 with a 3.12 ERA, wasn’t sharp, allowing six runs, five hits and five walks in five innings. He struck out two.

Joey Gallo, in a 2-for-36 skid, worked a leadoff walk to begin the third. After DJ LeMahieu grounded to short, Gleyber Torres singled to right to put runners at the corners. Matt Carpenter popped to short for the second out but Giancarlo Stanton worked a walk to load the bases. Donaldson then hit his sixth career grand slam, hitting a drive to dead center that he knew was gone off the bat. Hicks then ripped a shot into the Yankees’ bullpen for a 5-0 lead.

“Obviously, it was a big situation for us,” Donaldson said of the slam. “Gave us a little bit of a cushion there.”

More Yankees headlines

Newsday LogoYour Island. Your Community. Your News.Digital AccessOnly 25¢for 5 months