Cardinals starter Jake Westbrook left with a 2-0 lead after holding the Pirates scoreless for six innings, but Pittsburgh came to life against reliever Joe Kelly (0-1) in the seventh.
Pedro Alvarez led off with a walk and Martin followed by slicing a pitch the opposite way over the right-field wall, tying the contest.
Clint Barmes singled to right and went to second on a one-out walk to Starlin Marte that chased Kelly in favor of Trevor Rosenthal. Barmes and Marte advanced on a wild pitch and Rosenthal then hit Jose Tabata with a pitch to load the bases, and walked Andrew McCutchen to force in the go-ahead run.
Garrett Jones finished the rally with an RBI groundout.
A.J. Burnett (2-2) earned the win, yielding two runs on five hits over six frames. The right-hander walked three and struck out six.
Jason Grilli allowed a run in the ninth before collecting his 10th save.
Carlos Beltran and Pete Kozma supplied RBI for the Cards, whose four-game winning streak was snapped.