Tyler O'Neill hit a solo home run with two outs in the 10th inning and the St. Louis Cardinals held their playoff position, rallying past the San Francisco Giants 5-4 on Saturday.

Yadier Molina also homered for St. Louis, which began the day 1 ½ games ahead of Colorado for the second NL wild-card spot. The Cardinals, who have seven games remaining, started three games behind Milwaukee for the top wild-card slot.

More Images
St. Louis Cardinals' Tyler O'Neill (41) is congratulated by teammate Marcell Ozuna (23) after hitting a walk-off home run to defeat the San Francisco Giants 5-4 in the 10th inning of a baseball game Saturday, Sept. 22, 2018, in St. Louis. (AP PhotoJeff Roberson)

Tyler O'Neill hit a solo home run with two outs in the 10th inning and the St. Louis Cardinals held their playoff position, rallying past the San Francisco Giants 5-4 on Saturday.

St. Louis Cardinals first baseman Matt Carpenter, bottom, is unable to throw out San Francisco Giants' Gorkys Hernandez at first as Cardinals second baseman Yairo Munoz leaps during the 10th inning of a baseball game Saturday, Sept. 22, 2018, in St. Louis. Carpenter was charged with an error on the play. (AP PhotoJeff Roberson)

O'Neill hit his ninth homer, connecting off Mark Melancon (0-3) to give the Cardinals their 11th walk-off win of the season.

St. Louis Cardinals' Yadier Molina has his bat slip out of his hands as he strikes out to end the ninth inning of a baseball game against the San Francisco Giants Saturday, Sept. 22, 2018, in St. Louis. (AP PhotoJeff Roberson)

Molina tied it with a two-run homer off Dereck Rodriguez in the seventh inning. It was Molina's 19th home run, but only his second at home.

San Francisco Giants starting pitcher Dereck Rodriguez throws during the first inning of a baseball game against the St. Louis Cardinals, Saturday, Sept. 22, 2018, in St. Louis. (AP PhotoJeff Roberson)

TRAINER'S ROOM

St. Louis Cardinals starting pitcher Adam Wainwright (50) keeps his eye on a pop up single by San Francisco Giants' Joe Panik as Giants' Aramis Garcia, left, prepares to score from third during the third inning of a baseball game Saturday, Sept. 22, 2018, in St. Louis. (AP PhotoJeff Roberson)

UP NEXT

St. Louis Cardinals' Yadier Molina (4) is congratulated by teammate Jedd Gyorko (3) after hitting a two-run home run during the seventh inning of a baseball game against the San Francisco Giants, Saturday, Sept. 22, 2018, in St. Louis. (AP PhotoJeff Roberson)

St. Louis Cardinals' Yadier Molina (4) is congratulated by teammate Jedd Gyorko (3) after hitting a two-run home run during the seventh inning of a baseball game against the San Francisco Giants, Saturday, Sept. 22, 2018, in St. Louis. (AP PhotoJeff Roberson)

St. Louis won for the fifth time in six games. San Francisco has lost three in a row.

St. Louis Cardinals' Tyler O'Neill (41) is congratulated by teammate Marcell Ozuna (23) after hitting a walk-off home run to defeat the San Francisco Giants 5-4 in the 10th inning of a baseball game Saturday, Sept. 22, 2018, in St. Louis. (AP PhotoJeff Roberson)

St. Louis Cardinals' Tyler O'Neill (41) is congratulated by teammate Marcell Ozuna (23) after hitting a walk-off home run to defeat the San Francisco Giants 5-4 in the 10th inning of a baseball game Saturday, Sept. 22, 2018, in St. Louis. (AP PhotoJeff Roberson)

O'Neill hit his ninth homer, connecting off Mark Melancon (0-3) to give the Cardinals their 11th walk-off win of the season.

Carlos Martinez (8-6) pitched two scoreless innings.

Adam Wainwright, making his third start for St. Louis since elbow inflammation put him on the disabled list, gave up four earned runs on eight hits over 6 1-3 innings. He struck out six and did not walk a batter.

St. Louis Cardinals first baseman Matt Carpenter, bottom, is unable to throw out San Francisco Giants' Gorkys Hernandez at first as Cardinals second baseman Yairo Munoz leaps during the 10th inning of a baseball game Saturday, Sept. 22, 2018, in St. Louis. Carpenter was charged with an error on the play. (AP PhotoJeff Roberson)

St. Louis Cardinals first baseman Matt Carpenter, bottom, is unable to throw out San Francisco Giants' Gorkys Hernandez at first as Cardinals second baseman Yairo Munoz leaps during the 10th inning of a baseball game Saturday, Sept. 22, 2018, in St. Louis. Carpenter was charged with an error on the play. (AP PhotoJeff Roberson)

Molina tied it with a two-run homer off Dereck Rodriguez in the seventh inning. It was Molina's 19th home run, but only his second at home.

Aramis Garcia, who had four hits, gave the Giants a 3-2 lead with a two-run single off Wainwright in the seventh.

Rodriguez, the son of Hall of Fame catcher Ivan Rodriguez, gave up four runs on seven hits over six innings. He struck out two and walked one.

St. Louis Cardinals' Yadier Molina has his bat slip out of his hands as he strikes out to end the ninth inning of a baseball game against the San Francisco Giants Saturday, Sept. 22, 2018, in St. Louis. (AP PhotoJeff Roberson)

St. Louis Cardinals' Yadier Molina has his bat slip out of his hands as he strikes out to end the ninth inning of a baseball game against the San Francisco Giants Saturday, Sept. 22, 2018, in St. Louis. (AP PhotoJeff Roberson)

TRAINER'S ROOM

Cardinals: INF Kolten Wong was held out of the lineup as a precautionary measure. He left Friday's game with a sore hamstring and is listed as day-to-day.

"(He's) in pretty good shape," manager Mike Shildt said.

San Francisco Giants starting pitcher Dereck Rodriguez throws during the first inning of a baseball game against the St. Louis Cardinals, Saturday, Sept. 22, 2018, in St. Louis. (AP PhotoJeff Roberson)

San Francisco Giants starting pitcher Dereck Rodriguez throws during the first inning of a baseball game against the St. Louis Cardinals, Saturday, Sept. 22, 2018, in St. Louis. (AP PhotoJeff Roberson)

UP NEXT

RHP Miles Mikolas (16-4, 3.01) will face LHP Andrew Suarez (7-11, 4.24) in the final game of the three-game series on Sunday. Mikolas is 16-0 when receiving two or more runs of support. Suarez is 3-2 with a 2.67 ERA in his last five starts.

St. Louis Cardinals starting pitcher Adam Wainwright (50) keeps his eye on a pop up single by San Francisco Giants' Joe Panik as Giants' Aramis Garcia, left, prepares to score from third during the third inning of a baseball game Saturday, Sept. 22, 2018, in St. Louis. (AP PhotoJeff Roberson)

St. Louis Cardinals starting pitcher Adam Wainwright (50) keeps his eye on a pop up single by San Francisco Giants' Joe Panik as Giants' Aramis Garcia, left, prepares to score from third during the third inning of a baseball game Saturday, Sept. 22, 2018, in St. Louis. (AP PhotoJeff Roberson)

St. Louis Cardinals' Yadier Molina (4) is congratulated by teammate Jedd Gyorko (3) after hitting a two-run home run during the seventh inning of a baseball game against the San Francisco Giants, Saturday, Sept. 22, 2018, in St. Louis. (AP PhotoJeff Roberson)

St. Louis Cardinals' Yadier Molina (4) is congratulated by teammate Jedd Gyorko (3) after hitting a two-run home run during the seventh inning of a baseball game against the San Francisco Giants, Saturday, Sept. 22, 2018, in St. Louis. (AP PhotoJeff Roberson)