Snell, who didn’t earn a win in any of his first 15 starts this season, has now won four straight decisions and hasn’t taken a loss in his last 10 starts.

“I just learned I have to keep going -- you have to adapt, keep learning and keep making the adjustments you need to,” Snell said after Wednesday’s win. “I like the confidence that I had and kept believing in myself.”

The Rays (74-78) kept alive their slim hopes of an American League wild card, moving within four games of the Minnesota Twins with 10 games remaining and four other teams between them.

The first-place Cubs (84-67) had their longest win streak of the season end, and their lead over the second-place Brewers slipped to three games in the National League Central pending Milwaukee’s result Wednesday night. Chicago heads to Milwaukee for a huge four-game series this weekend.

“He grabbed his confidence and all the sudden it all come together for him,” Cubs manager Joe Maddon said of Snell. “He was good, he was very good.”

Snell (4-6) had perhaps his best outing of the season, erasing both of the hits he allowed with double plays immediately after. He walked three and struck out five. He hasn’t allowed any earned runs in three of his past six starts.

Cubs starter Jon Lester (11-8) was tagged for seven runs and eight hits in 4 1/3 innings, ending his run of three straight wins.

“Stuff-wise, command-wise, just an unfamiliar night,” Maddon said. “He had a tough night and I don’t know why. ... It just wasn’t there.”

The Rays had dropped eight of 11 but won Wednesday to split the four-game season series with the Cubs. The series finale drew a crowd of 24,238, among Tampa Bay’s largest this season.

Rays catcher Wilson Ramos went 3-for-4 with two RBIs, both on a fifth-inning single to help break the game open.

“Wilson was great back there, and I liked his game-calling, especially going inside,” Snell said. “He helped me a lot there. I felt all my pitches were working very well.”

Chicago spoiled the shutout with a run in the eighth on Jon Jay’s RBI single to bring in Mike Freeman, who had doubled. The Rays got the run back in the bottom of the eighth as Evan Longoria hit an RBI single for an 8-1 lead.

Steven Souza got things started for the Rays with a solo home run to left field in the first inning. It was his 30th of the season, extending his career high, and gave Tampa Bay an early 1-0 lead.

Lester got into trouble in the second. Ramos singled to start the inning, and after a one-out walk to Cesar Puello, the Rays got an RBI single from Brad Miller.

Peter Bourjos added an RBI bunt single, and Kevin Kiermaier contributed an RBI single for a 4-0 lead.

The Rays added three runs in the fifth, as Souza walked and twice was nearly picked off but wound up with stolen bases.

Lester’s pickoff attempt went high to first base and the ball was dropped, allowing Souza to escape to second. A throw to third that would have caught Souza between the bases was short and dropped, allowing Souza to reach third. Longoria was hit by a pitch and Logan Morrison walked to load the bases, and Ramos came through with a two-run single for a 6-0 lead.

Reliever Justin Grimm came in with a runner to third, and his first pitch was a passed ball that allowed a run to score to make it 7-0.

Lester left without finishing the fifth, failing to strike out any Rays batters even though Tampa Bay has fanned 1,457 times this season.