Kevin Pillar had four hits, including a go-ahead, two-run homer in the eighth inning, and San Francisco rallied to cool off the St. Louis Cardinals 9-8 Wednesday night.
Brandon Crawford and Mike Yastrzemski also homered for San Francisco, which snapped a four-game losing streak.
Paul Goldschmidt drove in four runs and Paul DeJong homered for St. Louis, which lost for just the fourth time in 18 games. St. Louis remained 2 1/2 games ahead of the Chicago Cubs in the NL Central.
Pillar had three RBIs. He hit a two-run homer off Giovanny Gallegos in the eighth.
Will Smith recorded four outs for his 31st save in 35 chances. He struck out Goldschmidt with the tying run at third to end the eighth, then punched out Harrison Bader with two on to end the game.
Goldschmidt hit a two-run triple in the fifth to tie it at 4. He also highlighted a four-run outburst in the sixth with a two-run double to give St. Louis an 8-7 lead.
Crawford hit a three-run homer in sixth to break a 4-4 tie.
San Francisco starter Madison Bumgarner allowed six runs and nine hits over five innings. He struck out two and walked one.
The 4 hour, 5-minute contest featured 28 hits, 13 pitchers and 365 pitches.
Dakota Hudson (14-6, 3.53) will face RHP Logan Webb (1-0, 3.52) in the final game of the four-game set Thursday afternoon. Hudson has won last four starts. Webb is making his fourth major league start. He has struck out seven in two of the three starts.