Matt Adams hit a three-run homer in the eighth inning to rally the St. Louis Cardinals to an 8-7 victory over the Pittsburgh Pirates on Monday night.

St. Louis, which overcame deficits of 4-0 and 6-4, moved two games ahead of the Los Angeles Dodgers in the race for the second wild card spot in the NL. Cincinnati beat Los Angeles 10-6 Monday.

Josh Harrison, Colin Moran and Starling Marte homered for Pittsburgh, which had its five-game winning streak snapped.

Adams homered off Edgar Santana (2-3) to erase a 6-4 deficit.

John Brebbia (2-3) picked up the win for St. Louis, which has won two in a row.

Carlos Martinez, a former starter, picked up his third save in as many chances. He gave up run-scoring double to Josh Bell with two out. But he got Francisco Cervelli to ground out to DeJong at deep short to end the game. The play was challenged, but Cervelli was ruled out after a video review.

St. Louis right-hander Adam Wainwright, making his first start since May 13, gave up four runs on seven hits in five innings. He retired the last eight batters after giving up three runs in the third.

Matt Carpenter walked to start the go-ahead rally. Jose Martinez followed with a hit to set the stage for Adams' heroics.

Harrison broke a 4-4 tie with a solo shot off Chasen Shreve in sixth. Adam Frazier added a run-scoring hit for a 6-4 lead.

The Cardinals scored four times in the fourth off Trevor Williams, who had allowed just four earned runs over his previous nine starts. Paul DeJong had a two-run double and scored on Harrison Bader's game-tying sacrifice fly.

Williams allowed six hits, struck out six and didn't walk a batter.

Moran homered in the second off Wainwright, who struck out three and did not walk a batter. Marte ripped a two-run shot in the third, his 19th of the season, for a 3-0 lead.

St. Louis is 33-18 under manager Mike Shildt, who took over for Mike Matheny on July 15.

TRAINER'S ROOM

Cardinals: C Yadier Molina missed his fourth straight game with left hamstring tightness suffered Wednesday in Washington. He is expected to return sometime during the current seven-game homestand that began on Monday. ... RHP Adam Wainwright was activated from the 60-day disabled list prior to the game.

UP NEXT

RHP Joe Musgrove (6-8, 3.75) takes on RHP Miles Mikolas (14-4, 3.06) in the second game of the three-game set on Tuesday. Musgrove has gone at least seven innings in five of his last nine starts. The Cardinals are 7-1 in Mikolas' last eight starts.