ST. LOUIS — Two weeks ago, St. Louis infielder Matt Adams couldn't buy a hit.
He struggled just to make contact, and was mired in a 0-for-27 slump.
Those days are apparently over.
Adams hit a three-run homer in the eighth inning on Monday night to rally the Cardinals to an 8-7 victory over the Pittsburgh Pirates.
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.
"He threw a slider middle of the plate, it stayed up and I put the barrel to it," Adams said.
Adams, a former Cardinals player claimed off waivers from Washington on Aug. 21, hit his first homer at Busch Stadium since Sept. 27, 2016. It was his 21st of the season, a career high.
St. Louis manager Mike Shildt remained confident in Adams despite his struggles. Adams struck out eight times during his hitless skid, which spanned Aug. 5-28.
"You have to have a short memory at this level," Adams said. "Or it tends to have a snowball effect."
John Brebbia (2-3) picked up the victory for St. Louis, which has won two in a row.
Carlos Martinez, a former starter, recorded his third save in as many chances. He gave up run-scoring double to Josh Bell with two out. But Martinez got Francisco Cervelli to ground out to Paul DeJong at deep short to end the game. The bang-bang play at first was challenged, but Cervelli was ruled out after a 31-second video review.
DeJong ranged onto the outfield grass to make the play.
"He knows the speed of the runner, he knows the speed of the ball," Shildt said. "He can beat you in a lot of different ways."
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.
"I've got to execute a lot better than I did today," Wainwright said. "It's good to be back competing. I love being out there."
Shildt said Wainwright will get another start.
"He's earned the opportunity to go again," Shildt said. "I trust his stuff, he's still making pitches."
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. 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. He was making his sixth start of the season against St. Louis.
"I'm just thankful I'm not pitching against the Cardinals again for the rest of the year," Williams said. "They're a great ball club and I wish them nothing but success going into October."
Williams came into the game on a big-time roll.
"It's been really a strong stretch," Pittsburgh manager Clint Hurdle said. "(Tonight) he rolled his sleeves up, went to work, stopped the bleeding that was going on."
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 Shildt, who took over for Mike Matheny on July 15.
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.
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.