Kevin Pillar is enjoying every minute of his career season.

ST. LOUIS (AP) — Kevin Pillar is enjoying every minute of his career season.

The Giants outfielder 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.

"Every time I hit one, it's still special," Pillar said. "They all feel like my first."

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.

"I've been able to do it more frequently this year," Pillar said. "It's the same feeling I've always wanted to have, always dreamed about doing since I was a little kid."

Pillar's 21st homer is well ahead of his previous best of 16 in 2017 with the Blue Jays. He has 79 RBIs, 20 more than his prior best last year with Toronto.

"A lot of times his (hits) are in big situations," Crawford said. "He's been huge for us this year."

A seven-year veteran, Pillar also singled in the third, fifth and sixth innings.

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.

The Giants were able to fight back after surrendering 4-0 and 7-4 leads.

"We found a way to win a ballgame against a very good team," San Francisco manager Bruce Bochy said. "You keep battling and these guys did it."

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.

"We just try and play the best we can," Goldschmidt said. "We just came up one run short."

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 go-ahead blast.

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.

"They did a great job of picking me up when I didn't do a lot for us," Bumgarner said. "I wasn't very good."

St. Louis starter Michael Wacha, working on three days of 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 4 hour, 5-minute contest featured 28 hits, 13 pitchers and 365 pitches.

POPULAR BIRDS

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.

TRAINER'S ROOM

Cardinals: C Matt Wieters, who has been slowed by calf strain, continues to make progress. He is hoping to begin baseball activities within the next few days.

UP NEXT

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.