CHICAGO — The Chicago Cubs had been scoring in bunches lately.

Then Sonny Gray took the mound for the Cincinnati Reds.

The Cubs were shut down by Gray and two relievers Tuesday night, falling 4-2 to the Reds in a loss that hurt their playoff positioning.

Chicago had won five in a row, outscoring its opponents 59-18 during the stretch. But it managed just two runs against Gray (11-7) before Michael Lorenzen and Raisel Iglesias closed out the five-hitter for Cincinnati.

“Sonny just keeps pitching great,” Reds manager David Bell said. “He went deep into the game against a great lineup. It doesn’t really matter who he’s facing right now, the best teams, the best lineups. He’s pitching with that much confidence.”

The Cubs (82-69) dropped into a tie for the second NL wild card with Milwaukee, which held off San Diego for a 3-1 victory. They also missed out on an opportunity to gain ground on NL Central-leading St. Louis, which lost 6-2 to Washington.

Gray, the former Yankees starter, also helped out the Mets, who gained a game on the Cubs after their 6-1 victory over the Diamondbacks and now trail Chicago and Milwaukee by four games in the race for the second wild-card spot in the NL.

Rookie Aristides Aquino hit his 16th homer for Cincinnati (71-81), and Joey Votto and Eugenio Suárez each drove in a run.

Gray struck out nine in 6²/₃ innings. The All-Star right-hander improved to 5-1 with a 1.46 ERA in his last nine outings.

“I felt pretty good out there today after I kind of got going,” Gray said.

Yu Darvish (6-7) struck out 13 in seven innings for Chicago, but was hurt by a slow start. Kyle Schwarber had three hits and two RBIs.

Darvish fanned 14 in his previous start, a 4-1 win at San Diego on Thursday. He has 217 Ks in 170 1/3 innings on the year.

“Yu is on quite a run right now, but unfortunately their guy is really good, too,” Cubs manager Joe Maddon said. “In spite of us swinging the bats well lately, Sonny did a nice job also.”

Gray departed with runners on the corners, and Lorenzen struck out Nicholas Castellanos to end the inning.

Lorenzen then worked the eighth before Iglesias pitched a perfect ninth for his 32nd save.

Darvish struck out the side in the first, but Cincinnati scored three times. Votto doubled home Josh VanMeter before Aquino hit a drive to left-center for his first homer since Sept. 2.

Aquino, who was recalled from the minors on Aug. 1, has six homers against Chicago in six games.

“I made a good pitch to Votto, but he’s a great hitter,” Darvish said. “For Aquino, that’s my mistake. I should throw a breaking ball.”

Gray helped himself in the fifth, reaching on a one-out single and eventually coming around on Suárez’s base hit to give Cincinnati a 4-2 lead.

All-Star catcher Willson Contreras started at first base in Chicago’s second game since Anthony Rizzo sprained his right ankle during Sunday’s 16-6 victory over Pittsburgh. Rizzo is wearing a walking boot for five to seven days, casting doubt on the slugger’s availability for the rest of the season.

Schwarber drove in Castellanos with a double in the first and a triple in the third.