Updated

Jason Motte survived a tumultuous ninth inning and the St. Louis Cardinals topped the Pittsburgh Pirates, 5-4, pulling within a game for the second wild card in the National League.

Rafael Furcal scored twice and Yadier Molina smashed the go-ahead, two-run double for the Cardinals, who lost the series opener on Friday, 2-1.

Lance Lynn received a no decision for St. Louis, lasting only 4 1/3 innings. He was charged for three runs on four hits and three walks. He did strike out eight, but his earned run average expanded to 6.58 over his last five starts.

"I threw the ball well all day," Lynn said. "You give up four hits and they cost you four runs, that's the tough part about it. You gotta make sure those hits don't cost you runs, especially where in the lineup that they cost me runs. You gotta make better pitches to those guys."

The Cardinals tagged Erik Bedard (7-13) for five runs, nine hits and three walks in 4 2/3 innings.

"What I'm hoping, in the large picture, is for our rotation to stabilize itself," Pirates manager Clint Hurdle said. "When you're contemplating taking your starter out three, four times in the in the last two weeks in the fifth inning, it's not the direction that you want to head."

The Pirates went 1-for-14 with runners in scoring position, stranding the bases loaded in the fourth inning and the tying run on third in the ninth.

Jordy Mercer had two hits and knocked in a pair of runs as the Pirates lost for the fourth time in six games.

After the Pirates tied the game with two runs in the fifth inning, the Cardinals quickly regained the lead in the bottom half of the inning.

Furcal led off the fifth with a base hit, then advanced to third when Allen Craig singled and David Freese walked with two outs. Molina stroked a two-run, ground-rule double to score two and put the Cardinals ahead.

Barret Browning (1-2), Trevor Rosenthal, Edward Mujica and Mitchell Boggs combined for 3 2/3 scoreless innings in relief to set up Motte in the ninth.

Motte gave up a leadoff single to Gaby Sanchez before Freese committed an error, allowing Yamaico Navarro to reach base, and Mercer was hit by a pitch to load the bases with no outs.

But the right-hander got Andrew McCutchen to ground into a fielder's choice, which scored a run, and struck out Garrett Jones with the tying run on third. Motte then induced a Josh Harrison ground out to escape the threat, seal the win and notch his 28th save.

"Wasn't exactly by design," Cardinals manager Mike Matheny said. "But he did a great job making pitches and getting a little bit nastier when he needed it and that's huge. Huge for his confidence and, needless to say, what that is for us."

The Cardinals took the early lead before recording an out. Furcal led off the first with a double and came home on Matt Carpenter's base hit.

Pittsburgh tied the game in the third after Mercer laced a two-out base hit to score Clint Barmes, who reached on a one-out single.

After Lynn struck out Barmes and Bedard to escape a bases-loaded jam in the fourth, the Cardinals took the lead in the bottom half of the inning. Freese started the inning with a walk before Molina and Shane Robinson delivered back-to-back doubles to give the Cardinals a 3-1 lead.

The Pirates tied the game in the fifth. Starling Marte led off with a single and scored when Mercer doubled. After Lynn was pulled for Browning, Mercer advanced to third on a wild pitch and scored when Jones lofted a sacrifice fly to right field.

Game Notes

Lynn is winless in his last four starts ... Bedard had won his previous two outings ... Pittsburgh left 10 runners on base ... St. Louis went 3-for-8 with runners in scoring position and stranded eight.