ST. LOUIS (AP) - Kevin Pillar had four hits, including a go-ahead, two-run homer in the eighth inning, and the San Francisco Giants 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.
Rookie right-hander Tyler Rogers (1-0) got his first career victory with 1 1/3 innings of scoreless relief.
Gallegos (3-2) went two months and 19 appearances without allowing a homer before giving up Giants rookie Mauricio Dubon's solo shot Monday. This was his first appearance since then.
Evan Longoria started the eighth-inning comeback with a leadoff single to set the stage for Pillar's 21st homer of the season.
The Giants held leads of 4-0 and 7-4. 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.
St. Louis starter Michael Wacha, working on three days rest, did not allow a run over two innings. He gave up two hits, struck out two and walked one in an opener role.
DeJong's 25th homer of the season in the fourth pulled St. Louis within 4-2. Yastrzemski's 19th homer of the season triggered a four-run outburst in third.
The Cardinals passed the three million mark in attendance for the 16th successive season with a crowd of 41,945. St. Louis, with 3,037,876, joined the Los Angeles Dodgers and New York Yankees as the only teams to pass the three million mark this season.
Giants: INF Pablo Sandoval had season-ending Tommy John surgery performed by Dr. Neal ElAttrache. He also had loose bodies removed from the back of his right elbow. ... RHP Reyes Moronta was moved to the 60-day injured list with a torn labrum in his right shoulder.
Cardinals: C Matt Wieters, who has been slowed by calf strain, continues to make progress. He is hoping to begin baseball actitivies within the next few days.
St. Louis RHP 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.