Mitch Keller allowed one run on five hits in six innings for the Pirates (62-73), who won their fourth straight game. He struck out eight and walked three.
Colin Holderman, Carmen Mlodzinski and Colin Selby (2-0) each threw a scoreless inning for Pittsburgh and David Bednar closed out the 10th inning his 30th save.
Willson Contreras hit a homer for the Cardinals (58-77), who lost for the 11th time in 15 games.
St. Louis starter Dakota Hudson allowed one run on three hits in seven innings while inducing 14 groundouts.
JoJo Romero (4-2) suffered the loss by giving up three runs (two earned) in the 10th.
The Pirates broke ahead 1-0 in the second inning when Peguero walked with two outs and scored on Alfonso Rivas' double.
The Cardinals got singles from Jordan Walker and Masyn Winn to start the third inning. But Lars Nootbaar lined out, Paul Goldschmidt struck out and Nolan Gorman flied out.
Tyler O'Neill hit a two-out double in the fourth inning and Tommy Edman walked, but Walker grounded out to end the threat.
Keller walked Nootbaar with one out and Gorman with two outs in the fifth inning, but induced Nolan Arenado's groundout to end the threat.
Contreras tied the game 1-1 with his sixth-inning homer.
Ke'Bryan Hayes led off the ninth inning with an infield single, then Connor Joe walked. But pinch hitter Miguel Andujar grounded into a double play and Endy Rodriguez struck out.
In the bottom of the inning Edman reached on an infield single with one out and took second on a throwing error. But Walker flied out and Winn lined out to send the game to extra innings.
The Pirates seized the game in the 10th. Peguero hit a single to move automatic runner Rodriguez and Andrew McCutchen reached on a deflected infield single to produce one run, then Romero threw a wild pitch to score another.
After Ji Hwan Bae reached on an infield single, Bryan Reynolds hit a sacrifice fly to make it 4-1.
Goldschmidt's sacrifice fly made it 4-2 in the bottom of the 10th before the Cardinals were retired.
—Field Level Media