PITTSBURGH --- Trevor Rosenthal knew what he needed.

"Either a strikeout or a ground ball," the St. Louis Cardinals closer said. "If I don't get either one then we're probably in trouble."

Rosenthal then got shortstop Jordy Mercer to bounce into a 1-2-3 double play with the bases loaded to end the game as the Cardinals slipped past the Pittsburgh Pirates 6-5 on Sunday night.

"I just wanted a fastball, keep it low in the zone and either get him to hit it on the ground or strike out," said Rosenthal, who notched his 10th save. "It couldn't have worked out any better, though I'm sure the rest of the guys in this clubhouse wish I could have got the job done sooner."

Rosenthal gave up center fielder Andrew McCutchen's RBI single in the ninth that made it a one-run game and the Pirates then loaded the bases with no outs. However, first baseman Ike Davis fouled out and Mercer hit a one-hopper back to Rosenthal.

"This felt like a walk-off win for us right there," St. Louis manager Mike Matheny said.

Pittsburgh manager Clint Hurdle, whose team leads the major leagues with five walk-off wins, thought his team could do it again in front of a national audience on ESPN, which was televising a Sunday night game from Pittsburgh for the first time since 1996.

"You come up there, you've got Davis and Mercer, two guys who are swinging the bat well, have gotten to a good place," Hurdle said. "We weren't able to cash in."

Right-hander Shelby Miller (5-2), backed by a four-run first inning, got through 5 1/3 shaky innings to win his fourth consecutive start.

Miller (5-2) allowed two runs on four hits while walking four and striking out two. He has issued 31 bases on balls in 44 2/3 innings this season. He has won his past two starts against the Pirates after losing his first five.

"I didn't have much but I gave it what I got and fortunately it was enough to help us get a win," Miller said. "It was a struggle for me. I didn't have very good command of my pitches and I had to kind of fight through it all night. You don't want to go out and walk four guys but the rest of the guys fought hard and we won the game."

First baseman Allen Craig, catcher Yadier Molina and outfielder Jon Jay each had two of the Cardinals' 11 hits. Craig and Molina hit consecutive RBI singles in the first-inning outburst against starter Charlie Morton (0-5).

The Cardinals (19-19) salvaged the finale of the three-game series to avoid their first three-game losing streak of the season.

"Hopefully, this is a spark," Matheny said. "We've been looking for that thing that can get us clicking."

Morton's streak of winless starts reached 14 despite shutting down the Cardinals after the first inning and making it through the sixth. In all, he gave up four runs (one earned) and seven hits with one walk and three strikeouts.

"I just tried to get back out there and put up zeroes after that first inning," Morton said. "We kept chipping away and we almost pulled it out but I can't give up four runs there, especially in the first inning. It put us in a bad spot from the start."

Mercer hit a two-run home run and a double for the Pirates. Third baseman Pedro Alvarez had three hits, and catcher Tony Sanchez added two hits.

NOTES: Pirates CF Andrew McCutchen returned to the lineup after missing Saturday's game with soreness in his left ankle. He went 1-for-2 with three walks. ... Pittsburgh LF Starling Marte was not in the lineup because of lower back tightness, which caused him to leave Saturday'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. ... St. Louis CF Peter Bourjos was out of the starting lineup because of a cut on his right wrist, though he entered as a sub. He was spiked Saturday while attempting to break up a double play. OF Jon Jay, who entered the game 8-for-16 in his career against Pittsburgh RHP Charlie Morton, started in center field and went 2-for-4. ... The Cardinals host the Chicago Cubs on Monday night in the opener of a four-game series with St. Louis LHP Tyler Lyons (0-2, 3.45) facing LHP Travis Wood (2-4, 4.75). ... The Pirates are off Monday before beginning a three-game series Tuesday night at Milwaukee.