The Yankees’ recipe for success against the Red Sox on Wednesday night: CC, the other C.C., and a dash of Didi.

CC Sabathia threw eight shutout innings, Chris Carter hit a three-run home run and Didi Gregorius added a solo shot as the Yankees topped the Red Sox, 8-0, before 44,380 at Yankee Stadium.

Sabathia (7-2) seems to be taking back the mantle of staff ace from the struggling Masahiro Tanaka. Sabathia allowed five hits, walked none and struck out five. The rejuvenated lefty retired the final 12 batters he faced and lowered his ERA to 3.66 in a 95-pitch gem.

Sabathia improved to 6-0 with a 1.25 ERA in seven starts after a Yankees loss this season.

“We needed this,” manager Joe Girardi said. “We lost a tough game [Tuesday] night. Just a big performance by CC. I think he takes a lot of pride in that. He’s been that guy his whole career that you could turn to when you needed a big win and he still does it.”

Carter (3-for-4, four RBIs), who general manager Brian Cashman warned on Tuesday was in danger of losing playing time for non-production, crushed a long home run to left off reigning AL Cy Young award winner Rick Porcello in the Yankees’ four-run fourth. Carter also had an RBI single in the eighth.

advertisement | advertise on newsday

“It’d be good to get that bat going,” Girardi said. “It’s a big bat.”

Carter homered on Tuesday as the Yankees lost to Boston and saw their AL East lead drop to one over the Red Sox. It’s back to two going into Thursday’s series finale in the Red Sox’s first visit to the Bronx in the post-David Ortiz era.

Gregorius began the scoring with a leadoff home run in the third off Porcello (3-8), who was charged with six runs (five earned) in 6 1/3 innings.

The Yankees made it 2-0 in the fourth when Starlin Castro tripled and scored on Gary Sanchez’s single.

Carter, last year’s co-leader in the National League with 41 home runs for Milwaukee, hit a three-run blast later in the inning to give the Yankees a 5-0 lead. It was Carter’s sixth home run.

Yankees videos

Carter was robbed of another potential homer when Mookie Betts scaled the wall in right to haul in his long drive for the last out of the sixth. The ball hit the hand of a fan and went right into Betts’ glove as he leaped to the top of the wall.

Girardi asked the umpires for a video review, but said he was told he made the request too late.

The rest of the evening belonged to Sabathia, who got the final two outs of the fourth inning without the huge right knee brace he wears under his uniform. Sabathia took it off on the mound when a strap broke after he recorded the first out of the inning.

“That was really weird,” Sabathia said. “It was scary. I didn’t know what to expect, but I didn’t feel any pain, didn’t feel anything, so it was good.”

Yankees trainer Steve Donohue repaired the brace between innings and Sabathia pitched with it from there.

advertisement | advertise on newsday

Sabathia performed a great escape act in the fifth after Josh Rutledge led off with a long drive to center that was misplayed by Aaron Hicks into a triple.

Jackie Bradley Jr. hit a comebacker that Sabathia grabbed with his bare hand and threw to first for the first out. According to MLB.com, the ball had an exit velocity of 97.8 miles per hour.

“It was just right there,” Sabathia said. “So I grabbed it. It was a big play at the time.”

Sabathia next got Deven Marrero out on a short fly to right and concluded the inning by retiring Betts on a pop to short.

The Yankees added a run in the seventh on an RBI single by Matt Holliday. Carter and Brett Gardner had run-scoring singles in the eighth.