SAN FRANCISCO (AP) — Pablo Sandoval had no problem legging out his first triple in more than three years. Diving into home plate moments later was another matter and could land the Giants infielder on the disabled list with a right hamstring strain.

Right fielder Andrew McCutchen's bruised left foot may also be an issue — yet another blow for a team already beset by injuries much of the season.

Buster Posey had four hits, including a three-run double to help San Francisco break out of a collective funk, and the Giants beat the Milwaukee Brewers 8-5 on Sunday to avoid a four-game sweep.

"It's part of the game, it's going to happen," Posey said of San Francisco's bittersweet victory. "Even on the years where we've won the World Series we dealt with injuries. It's nothing that we can't handle."

Sandoval has played three positions in the infield this season but has been primarily at first base since Brandon Belt went on the DL with a hyperextended knee Thursday.

Sandoval hit a two-run triple in the fifth inning but got hurt while scoring on Steven Duggar's sacrifice fly. He will undergo an MRI test Monday when the Giants travel to San Diego.

"When I slid into home plate I felt something," Sandoval said. "It's not in the running. When I tried diving, I felt something. We're going to do an MRI and see what's going on."

McCutchen was removed for a pinch-hitter in the bottom of the eighth after fouling multiple pitches off his left foot.

That tempered an otherwise breakout day for San Francisco.

Gorkys Hernandez hit his 12th home run and scored twice, Brandon Crawford had two hits and Evan Longoria had a sacrifice fly, his first RBI since spending more than a month on the disabled list.

The Giants had lost four straight and six of seven before winning on a day when they didn't have manager Bruce Bochy. Bochy left the team late Friday to attend the Hall of Fame ceremonies in Cooperstown, New York, leaving bench coach Hensley Meulens as interim manager.

"That was what we were hoping for yesterday when we shuffled things around a little bit," Meulens said. "It was really nice to see these guys put some runs on the board so we could break that spell."

Andrew Suarez (4-6) allowed four runs in six innings for his first win since June 29.

Ryan Braun, Travis Shaw and Hernan Perez homered for Milwaukee. Christian Yelich singled to extend his hitting streak to 13 games.

San Francisco had been held to two or fewer runs in 11 of its 22 games in July before breaking out against Milwaukee starter Junior Guerra in the third.

Guerra (6-7) walked three consecutive batters before Posey lined a pitch into left-center to give the Giants a 3-2 lead. After Brandon Crawford's single, Longoria hit a sacrifice fly.

Hernandez homered off Guerra in the fourth after Steven Duggar and Alen Hanson struck out.

"Three of four on the road is good for sure," Brewers manager Craig Counsell said. "It was just that (third) inning was a weird inning ... but they capitalized on it."

MOVING UP THE CHARTS

Bochy was credited with the managerial win, even though he wasn't in attendance. It's the 1,906th win of Bochy's career, moving him past Hall of Famer Casey Stengel into sole possession of 11th place on the all-time list.

"How about that," Posey said with a grin. "Wasn't even here for it."

THIS AND THAT

Sandoval's triple was his first since June 14, 2015. . Shaw's home run was the first of his career as a pinch-hitter. . Brewers third baseman Mike Moustakas is 2-for-9 since being acquired from Kansas City.

TRAINER'S ROOM

Giants: Team officials are awaiting results after RHP Johnny Cueto met with doctors regarding his sore elbow. Cueto is winless in four starts since coming off a two-month stay on the disabled list. ... RHP Hunter Strickland (fractured right hand) threw off a mound in the bullpen before the game.

UP NEXT

Brewers: RHP Freddy Peralta (4-2, 3.74 ERA) makes his second start since getting called up from the minors when Milwaukee begins a four-game series against the Dodgers on Monday. Peralta is holding opponents to a .150 batting average.

Giants: LHP Derek Holland (5-8, 3.92) returns to the rotation and will pitch the opener of a two-game series in San Diego on Monday. Holland had been working out of the bullpen since the beginning of July.