ST. LOUIS — The Chicago Cubs went into Tuesday night's game against St. Louis with a chance to clinch the NL Central. The Cardinals did everything they could to keep that from happening.

The Cardinals hit four home runs and were able to withstand a late Cubs' rally for an 8-7 victory.

"I thought they did a real nice job putting the pressure on early and keeping it going," Cardinals manager Mike Matheny said. "That's the team we've got — they are going to keep coming. You might see a day like we had yesterday, not many of them, but we came back out and we needed everything we had today and they left it all out there."

Tommy Pham and Randal Grichuk homered and drove in two runs each and Matt Carpenter and Jedd Gyorko also homered for St. Louis, which remains 2 1/2 games behind the second Wild Card spot.

Zach Duke (1-1) got the win with 1 2/3 innings of scoreless relief. Juan Nicasio earned his fifth save.

The Cardinals scored five runs in the first two innings off Cubs ace Jake Arrieta, a scoring burst started by Carpenter's lead-off home run, his 23rd, and capped by Pham's two-run homer, his 23rd.

"You can certainly just show up today flat and roll over and just let them have their way with you but when you come out like we did, boom, 5-1 and send a message like 'Hey we're not just going to give this to you,'" Carpenter said. "That being said you have to credit to them. They never quit either. It was a grind and certainly they're going to fight to the end."

The Cubs were seeking to clinch the Central Division with either a win or a Milwaukee loss against Cincinnati, but the Brewers beat the Reds 7-6.

"I loved the comeback, I loved the energy," Cubs manager Joe Madden said. "Jake had a tough night. We continued to battle all the way through. . There were a lot of positives."

Cardinals right-hander Carlos Martinez allowed three runs (two earned) and four hits in 4 1/3 innings. Arrieta (14-10) allowed five runs (three earned) and six hits in three innings, his second shortest outing this season.

Gyorko and Grichuk both hit solo home runs in the seventh, extending the Cardinals' lead to 8-3. Gyorko's home run was his 20th. Grichuk's his 21st.

Jason Heyward hit a three-run home run, his 11th, off reliever John Brebbia in the eighth to cut the deficit to 8-6. Ben Zobrist hit a solo homer off Brebbia, his 12th, to make it 8-7.

The Cubs had the tying run on second base with two outs in the ninth but Nicassio struck out Javier Baez to secure the victory.

YADIER MOLINA OUT

Cardinals C Yadier Molina left Monday's game after taking two foul balls to the catcher's mask. He's expected to rest 48 hours, as part of the concussion protocol, and will then be reevaluated.

"I've been hit in the head many times but not twice in a row like last night," Molina said. "Last night was pretty bad. I was in pain. I was confused. The nausea went away. I'm resting for two days then we are going to test it again."

TRAINER'S ROOM

Cubs: 2B Baez (knee soreness) left Monday's game after fouling a pitch off his right leg and was not in the starting lineup on Tuesday but pinch hit in the ninth. ... CF Albert Almora left the game in the fifth after stumbling and falling into the centre field wall while chasing Paul DeJong's double. The Cubs announced he had a right shoulder contusion and X-rays were negative.

Cardinals: 1B Jose Martinez (thumb) returned as a pinch-hitter after missing the previous three games. ... Pham was pinch-hit for in the eighth inning. The Cardinals announced he had a left side contusion after being hit by a pitch in the sixth inning.

"He seems confident that it just kind of spasmed up, right on the spot where he was hit, and we're hopeful for tomorrow," Matheny said.

UP NEXT

Cubs: RHP John Lackey (11-11, 4.67) is 6-2 with a 3.88 ERA in 12 starts since the All-Star break. The Cubs are 11-2 in Lackey's last 13 starts.

Cardinals: RHP Michael Wacha (12-8, 4.00) is 4-6 with a 6.32 ERA in 15 career games, including 13 starts, against the Cubs.