Team up with us for 99¢

CHICAGO • Whatever the Cardinals gained in the standings and Matt Carpenter seized by rescuing them from catastrophe, their elation was limited late Thursday night by the reason Carpenter was in the game to win the game at all.

A midgame substitute for injured infielder Kolten Wong, Carpenter came up in the 10th inning shortly after the Cardinals and closer Carlos Martinez had a three-run lead pickpocketed in the bottom of the ninth. Carpenter drilled the first pitch he saw to regain the lead and send the Cardinals to a 5-4 victory at Wrigley Field, their first win at the Confines this season. Carpenter’s home run rewarded Jack Flaherty’s dominant eight innings and kept the Cardinals from losing Wong, losing the lead, losing the game, and losing ground in their race to reclaim the National League Central throne from usurpers — all on the same night.

“It was a gut punch that inning before,” Carpenter said. “Jack pitched so great. We had that game locked down. And then it squeaked away from us. They tied it up. Just the emotional turn of being able to get the lead again. Looking in (the dugout) and the excitement. Just fired up for everybody.”

The win widened the Cardinals’ lead on the Cubs to four games even as it dropped the archrivals to third place in the division, a game behind Milwaukee. The Cardinals (86-67) assured that no matter what happens in the three games remaining at Wrigley, they will leave Chicago with a grip on a postseason berth. Their magic number to clinch the division title for the first time since 2015 is seven. The Cubs (82-71) cannot catch them — this weekend, .

Whether Wong will rejoin the division race is unclear.

The Cardinals’ second baseman, who one teammate called the “MVP of the team” for his .342 average since the All-Star break and rise to No. 2 in the order, will have an MRI taken of his left hamstring Friday morning. The initial diagnosis is a mild tear of the muscle, though manager Mike Shildt acknowledged that could describe a spectrum of severities. He is not expected to play for several days as the team determines in the next 24 to 48 hours the extent of the injury. In his absence, the Cardinals intend to turn to rookie Tommy Edman, who scored twice Thursday, at second and likely return Carpenter to third, where he played before prolonged struggles put him on the bench this month.

Carpenter told Shildt “I’m going to be ready to go today and be whatever that role is moving forward,” the manager recalled. “He backed his words up.”

Flaherty pitched eight innings and cut his ERA below 3.00 for the first time since his third start. He had the Cubs leery of his slider and frozen by his fastball as he struck out eight and completed his 12th quality start in his past 14 appearances. Since the All-Star break he has a 1.07 ERA, and he was on his way to an 11th win when the ninth caved in on Martinez. The first two batters reached. A double off first base and down the line by Ben Zobrist put the tying run in scoring position. An infield single brought home pinch runner Javier Baez and ejected Martinez from the game short of his 22nd save. Jason Heyward tied the game on a groundout as lefty Andrew Miller wiggled free of the ninth, holding a 4-4 game.

The Cardinals were on the brink of another way to lose at Wrigley, a ballpark that has vexed them all season. They had been 0-6 amidst the ivy.

“This is a different team that we’re bringing in than some of those other teams coming in here,” Shildt cautioned before the game. “I feel good about what we’re bringing. I think we’ve grown. There’s no question. This team has gotten better as the season’s gone on. That’s what we do.”

Take Edman, for example.

Edman made his major-league debut at Wrigley as a utility infielder, and in the months since he’s become an everyday player. He had a leadoff triple that eventually broke a 1-1 tie in the game, and he had a diving stop in the ninth to help keep the game tied. Harrison Bader, who had two RBIs, has been to Class AAA and back since the Cardinals visited Wrigley last, and after a telling walk that showed a command of the strike zone he had two RBI hits as the Cardinals pulled ahead, 4-1.

All Flaherty has done since the Cardinals last played at Wrigley is muscle the Cardinals into the division lead with the most dominant second half of pitching this division has seen since Jake Arrieta won the Cy Young Award in 2015.

“I can’t imagine who is a better pitcher in baseball right now,” Edman said.

“You come in with confidence, playing our game,” Flaherty said. “Mentally, yeah, mentally (it’s different). We came in here in June. I didn’t have my best stuff. Trying to throw that stuff out and move on and act like that never happened.”

Flaherty was warming up, Shildt was in the dugout, and the game was a few minutes from first pitch when the Cubs orchestrated the theatric, unexpected return of Anthony Rizzo. Four days after spraining his ankle, three days after the team said he would spend the weekend in a protective boot, and 20 minutes before first pitch, Rizzo was in the lineup. Flaherty figured the Cubs “needed a little bit of a jolt there,” and they got it from Rizzo. The lone run Flaherty allowed in his three-hit start was a solo homer to Rizzo that tied the game in the third.

Flaherty retired the next 10 Cubs.

Carpenter was on the bench throughout the early innings, readying he figured for a late-game, pinch-hit at-bat. He had his cleats on in the fifth when Wong limped back after trying to leg out a groundball. He did not have his glove. He had not gone through any of his usual warmup routine.

“Not a lot of time to think or get ready,” Carpenter said. “Just play.”

Had he been a pinch-hitter in the game he would have appeared earlier than the 10th and likely later in the order than second. But as a sub for Wong, Carpenter’s turn came up in the 10th against Cubs closer Craig Kimbrel, back from injury.

Carpenter hunted fastball. Got it. Put it in the center-field seats.

Flaherty was far enough removed from his start to doing his cool down, but close enough to hear the dugout.

“Willing it to get out, get out, get out,” Flaherty said. “It was awesome. Just pure joy. Happiness, man. Ain’t nothing else.”

Keep up with the latest Cardinals coverage from our award-winning team of reporters and columnists.