Allen Craig and Yadier Molina had two hits each, including RBI singles in a four-run first inning. Craig went 5-for-11 in the three-game series after entering with a .202 batting average. Molina was 0-for-12 in his previous four games.
Miller (5-2) walked four and allowed four hits in 5 1-3 innings, but held the Pirates to just two runs — which came on Jordy Mercer's first home run of the season in the fourth inning.
Rosenthal gave up a run in the ninth that made it 5-4, but got Mercer to hit into a 1-2-3 double play to end it.
Charlie Morton (0-5) was charged with only one earned run of the four he allowed over six innings but remained winless since Sept. 2, a span of 14 starts.
Pittsburgh's Pedro Alvarez had three hits.
Rosenthal survived an RBI single by Andrew McCutchen to notch his 10th save as the Cardinals avoided their first three-game losing streak of the season.
Mark Ellis also had an RBI single in the first inning for St. Louis and Craig added a sacrifice fly.
Mercer cut the Pirates' deficit in half to 4-2 in the fourth inning when he a two-run home run to left field, his first of the season.
Alvarez pulled Pittsburgh within a run in the seventh with an RBI single.
The Pirates scored in the bottom of the eighth on Sanchez's groundout.
NOTES: Andrew McCutchen returned to the lineup after missing Saturday's game with soreness in his left ankle. ... Pittsburgh LF Starling Marte was not in the lineup because of lower back tightness, which caused him to leave Saturday night's game in the fourth inning. ... Pirates RF Travis Snider batted leadoff after missing the previous two games while serving a suspension from Major League Baseball for his actions April 20 in a benches-clearing brawl with the Milwaukee Brewers. ... Bourjos, who started the previous four games, did not start because of a cut on his right wrist that came as a result of getting spiked Saturday night while attempting to break up a double play. However, he entered the game in the game in the seventh inning as a defensive replacement. ... The Cardinals host the Chicago Cubs on Monday night in the opener of a four-game series with LHP Tyler Lyons (0-2, 3.45) facing LHP Travis Wood (2-4, 4.75). ... The Pirates are off Monday then begin a three-game series Tuesday night at Milwaukee.
Link to box score: St. Louis (19-19) 6 at Pittsburgh (12-17) 5
Join the pre-game, in-game and post-game discussion about each contest at The Cardinal Nation message board.