PITTSBURGH — Down to his final strike and his team trailing by a run with two outs in the ninth, St. Louis pinch-hitter Matt Carpenter told himself to just find a pitch he could handle.

When the fastball from closer Tony Watson ended up right down the middle and not up and away as Watson hoped, Carpenter pounced. His solo homer — a major league record 15th by a St. Louis pinch-hitter this season — tied it and sent a jolt through the Cardinals. A home run each from Randal Grichuk and Jhonny Peralta followed, and St. Louis rallied for a stunning 9-7 win over the Pittsburgh Pirates on Tuesday night.

“We’ve got a team that I think the best way to describe it is a dangerous team,” Carpenter said. “We’ve got a team that I don’t think anybody wants to match up with, especially in a postseason scenario. It’s a fun team to play on. We never quit, and tonight was a good example of it.”

St. Louis blew an early five-run lead and the Pirates were a pitch away from ending a seven-game losing streak when Watson’s 0-2 fastball turned into Carpenter’s 18th home run. An All-Star two years ago as a setup man who moved into the closer role when Mark Melancon was traded to Washington at the deadline, Watson gave up as many homers in the ninth as he did during the entire 2015 season.

“We’re not playing good ball and to go out there and (have) guys fight back and be a strike away and serve up four more runs, it’s tough to swallow,” Watson (2-4) said after his third blown save since replacing Melancon.

Yadier Molina went 4 for 5, including a first-inning grand slam for St. Louis. Mike Mayers (1-1) tossed a scoreless eighth for the win, and Seung-Hwan Oh worked around a solo homer to Jung Ho Kang in the ninth for his 16th save.

The Cardinals finished with five home runs in all, including Matt Adams’ 436-foot drive over the seats in right field that plopped into the Allegheny River on the bounce. The comeback allowed St. Louis to remain a game in front of the New York Mets for the second wild card in the National League.

“I’m speechless,” St. Louis manager Mike Matheny said. “Just, I love how this team competes, right down to the last out. Having a guy like (Carpenter), who hadn’t felt quite right, to be able to come into that situation, and then right after that … I’m at a loss.”

Jung Ho Kang had two homers for Pittsburgh and Jordy Mercer hit a two-run double in the fifth as the Pirates took advantage of some sloppy defense by the Cardinals to overcome an early five-run deficit. Watson’s implosion, however, sent Pittsburgh to its eighth straight defeat.

The Pirates came in reeling during their longest skid in two years, one that dropped them to the fringe of playoff contention. Opponents have outscored them 47-22 during the slide, including a 12-6 setback on Monday night in which the Cardinals simply overpowered Pittsburgh’s struggling pitching staff.

It looked like more of the same early on Tuesday. The Cardinals loaded the bases against Ryan Vogelsong and Molina cleared them with his first grand slam since 2012, the 25th straight game the Cardinals have homered, a club record.

MARTINEZ FINALLY ARRIVES

St. Louis rookie outfielder Jose Martinez made his long-awaited major league debut when he entered as a pinch-hitter in the seventh. The 28-year-old son of former major leaguer Carlos “Café” Martinez grounded out to third in his first plate appearance after more than a decade in the minors.

“It was good to see him get that chance,” Matheny said. “This is a good day for him. Long time coming.”

TRAINING ROOM

Cardinals: RF Stephen Piscotty was initially held out of the lineup to give his aching left wrist a breather. Piscotty took a pitch off the wrist on Monday. Postgame X-rays were negative and Piscotty doubled as a pinch-hitter in the eighth.

Pirates: Pittsburgh held C Francisco Cervelli out of the lineup a day after he experienced discomfort in his left hand trying to block a pitch.

UP NEXT

Cardinals: Mike Leake returns to the rotation after a stay on the disabled list while battling a case of the shingles. Leake is 9-5 with a 3.28 ERA in his career against Pittsburgh but is 1-2 with a 5.71 ERA this season.

Pirates: Rookie Jameson Taillon will face the Cardinals for the first time in the series finale. The 24-year-old has a 2.80 ERA over his last 10 starts and pitched six innings of one-run ball last week against Milwaukee.