In upping his record to 16-9, Martinez retired 13 straight hitters at one point, recording all but two of his outs via balls in the infield or strikeouts. Jonathan Broxton and Miguel Socolovich completed the shutout, which was held up by a 47-minute rain delay before the bottom of the eighth.
The Cardinals blew the game open with four runs in the sixth off reliever Trevor Williams. Yadier Molina and Stephen Piscotty recorded consecutive RBI doubles, followed by Brandon Moss' two-run homer to right -- his 28th of the year.
St. Louis collected two more in the seventh. Matt Holliday, pinch-hitting for Martinez, lined a homer to right-center in his first at-bat since August 11. Molina's double play ball chased Matt Carpenter home with the final run.
Tyler Glasnow (0-2) gave up just one hit and one run in five innings, walking four and fanning four, but was tagged with the loss.
The Cardinals (84-76) edged within a half-game of San Francisco for the second wild-card spot, pending the outcome of the Giants' game with the Los Angeles Dodgers. They stayed two games behind the New York Mets for the first wild card.
Pittsburgh (78-81) clinched its first losing season since 2012.
For the first time since Saturday, St. Louis scored first. Jedd Gyorko pounded a 2-0 fastball 393 feet to left field in the bottom of the third for his team-high 29th homer of the year and his 22nd homer since the All-Star break.
It was the only hit the Cardinals managed through five innings off rookie right-hander Tyler Glasnow, who overcame four walks and a hit batter. Glasnow fanned four and extracted nine outs via grounders.
But Pittsburgh couldn't do anything with Carlos Martinez through five innings, as St. Louis' top starter this year allowed just three hits and fanned six. Martinez retired 12 in a row after a Sean Rodriguez single in the second.
NOTES: St. Louis Friday activated LF Matt Holliday (right thumb fracture) from the 15-day DL, but general manager John Mozeliak said the club isn't likely to pick up Holliday's option for 2017, so this is probably his last weekend in a Cardinal uniform. ... Pittsburgh LF Starling Marte (lower back) won't play this weekend, according to manager Clint Hurdle. Marte has missed 21 of the last 24 games. ... St. Louis has opted to start RHP Michael Wacha Saturday, his first start since Aug. 8. Wacha replaces Jaime Garcia, who has lost five straight decisions.