NEW YORK — CC Sabathia’s cutter was back, and the big left-hander returned to the win column for just the second time since the All-Star break.

Didi Gregorius and Aaron Hicks hit two-run homers to help the New York Yankees build a six-run lead and take another step toward their second straight AL wild card with a 10-8 victory over the Baltimore Orioles on Friday night.

Aaron Judge drove in a run for the first time since he returned from the disabled list on Sept. 14, and New York overcame a series of bullpen stumbles to lower its magic number to two over Tampa Bay for ensuring a wild-card game on Oct. 3. The Yankees likely will play Oakland and lead the Athletics by 1½ games for home-field advantage.

“I think we’re whole again,” Sabathia said in a reference to the return of Judge and closer Aroldis Chapman.

Backed by a 6-0 lead, Sabathia (8-7) allowed two runs in six innings and improved to 20-11 against Baltimore. He had been 1-4 in his prior 11 starts this season.

“I thought he commanded his slider and his change and his cutter just a little bit better,” manager Aaron Boone said. “He was generating that weak contact that we’re used to seeing from him.”

Sabathia, the Vallejo High grad, struck out five and raised his total to 2,981 . The 38-year-old wasn’t sure earlier this season whether he would return in 2019 for a 19th season but has made up his mind.

“I’m going to play next year,” he said.

Gregorius hit his 27th homer in the first and Hicks added his 25th in a four-run fourth off rookie Yefry Ramirez (1-7), who is 0-4 in 10 starts since beating Boston on July 24. Pitching with cut on his right thumb, Ramirez gave up six runs, six hits and three walks in 3 2/3 innings and fell to 0-3 against New York.

Baltimore closed to 6-4 on Adam Jones’ two-run single in the fifth, Austin Wynn’s homer against Jonathan Loaisiga and Jonathan Villar’s RBI single against former Oriole Zach Britton later in the seventh.

Voit singled off Cody Carroll in a three-run bottom half that put New York ahead 9-4, but Renato Nunez had a two-run homer against A.J. Cole in the eighth and DJ Stewart hit a two-run homer on David Robertson’s first pitch as Baltimore closed within a run. Dellin Betances pitched the ninth for his fourth save .

“We’re playing as good as we can,” Sabathia said. “The more we play together as a whole unit, I think we’ll just start to get better and better.”

Asked whether he’d want a couple work weeks before the playoffs, Sabathia smiled.

“No. The season’s way too long,” he said, including a profanity for emphasis.