The game had been deadlocked at 1-1 since the third, but the Pirates finally broke through for a run in the 11th against Kevin Siegrist (0-1).
Siegrist made a stab at it, but the ball bounced off his glove and into left field, allowing Martin to trot home with the winning run as the Pirates vaulted over the Cardinals into first place in the National League Central by one-half game.
Vin Mazzaro (6-2) earned the decision after starter A.J. Burnett and three Pirates relievers had combined to allow just one run over 10 innings.
Pedro Alvarez also drove in a run for the Bucs, who took a second straight in a crucial four-game divisional series, notching their seventh triumph in 10 games overall.
Lance Lynn yielded one run on three hits over six innings for St. Louis, which dropped a fifth straight.
Gal Gadot cast as Wonder Woman for 'Batman vs. Superman'
Benedict Cumberbatch's dramatic reading of R. Kelly lyrics is just what you need