KANSAS CITY, Mo. — Gary Sanchez and Chris Carter hit home runs Tuesday night, which was all well and good.

But hitting hasn’t been much of a problem this season, including during the weekend, when the Yankees lost three of four to the Astros. The Bombers did, after all, tally 21 runs the last two games of the series.

Far and away the most encouraging aspect of Tuesday night’s 7-1 victory over the Royals in front of 30,878 at Kauffman Stadium took place on the mound.

That’s where CC Sabathia put an emphatic stop to a personal four-game slump, pitching 6 2⁄3 shutout innings to give the Yankees (23-13) a positive start to a six-game trip.

“This team is playing well, you want to be a part of it and not the reason we’re losing a game once a week,” said Sabathia, 0-2 with a 9.58 ERA in his four previous starts. “Feels good to get a win.”

Sabathia resembled the pitcher who was 2-0 with a 1.47 record after three starts, allowing five hits and two walks. The 36-year-old struck out four as he improved to 3-2 with a 4.93 ERA.

advertisement | advertise on newsday

“I think it was important for him,” Joe Girardi said. “He was pretty frustrated with the way things were going and not being able to pitch the way he was early in season, so I think it was pretty important.”

Tyler Clippard took over for not-too-pleased-looking Sabathia with two outs in the seventh and the bases loaded and struck out Whit Merrifield.

“I understand,” Sabathia said of Girardi’s decision. “But I never want to come out in the middle of an inning.”

The offense banged out 13 hits, getting home runs from Sanchez and Carter, who had three hits. Sanchez, Starlin Castro, Aaron Judge and Didi Gregorius added two hits each.

“I’ve said about this offense,” Girardi said, “it can come from a lot of different places.”

Yankees videos

Sabathia’s was an especially welcome performance after Luis Severino lasted only 2 1⁄3 innings in the first game of Sunday’s doubleheader against Houston, an 11-6 victory, and Masahiro Tanaka’s 1 2⁄3-inning train wreck in the second game, a 10-7 loss in which the ace allowed eight runs.

The Royals (16-22), who came into the game with the American League’s worst offense (119 runs), did not get their first runner into scoring position until the seventh when Eric Hosmer led off with a double. Sabathia, with a far better cutter than in his last four starts, struck out Salvador Perez and Jorge Bonifacio on sliders but walked Jorge Soler and allowed an infield single to Alex Gordon to load the bases.

In came Clippard, who got out of the jam.

“The key today, honestly, all of his pitches were working nicely,” Sanchez said of Sabathia’s effectiveness, which allowed him to be at only 45 pitches through four innings. “His cutter, his fastball, everything. When you have control like that, you’re going to be successful.”

Sabathia got an early boost from Sanchez, who hit a three-run homer in the third, and from Carter, who came in hitting .200 and slugging .308 but who belted a two-run shot in the fourth that made it 5-0.

advertisement | advertise on newsday

Both blows came off righthander Jason Hammel, who came in 1-4 with a 5.97 ERA and pitched to those numbers. He allowed five runs, nine hits and a walk and did not strike out a batter in six innings.

The Royals avoided a shutout in the ninth, pushing one run across against Jonathan Holder to make it 7-1.

Sabathia received help in the field, notably by third baseman Chase Headley, shortstop Gregorius, and leftfielder Brett Gardner, who threw out Soler trying to stretch a fifth-inning single.

“These guys played some great defense behind me and Sanchy called a great game,” Sabathia said. “I got lucky in a way with these guys picking me up big-time.”