Sandy Rosario (3-1) was charged with the winning run on three hits in his one inning on the mound.

Miami took a 6-5 lead in their last turn at the plate, as Ed Lucas started with a base hit and was able to cross home before Mathis was tagged out at third trying to stretch his RBI double.

Cishek yielded a long single with one out to Hector Sanchez, but he was erased on a game-ending double-play grounder from Buster Posey.

Pence's two-run shot to dead center gave the Giants the lead in the opening frame.

Mathis kicked off the home third with a shot to left which halved Miami's deficit, then RBI singles from Lucas and Hechavarria in the fourth put the Marlins ahead 3-2.

Pence's two-out single in the fifth plated Gregor Blanco to tie the game, but the hosts forged ahead in the home half when Giants starter Madison Bumgarner uncorked a wild pitch during a walk to Justin Ruggiano which allowed Solano to come in.

"It seemed like almost every pitch I threw was a hair off in the wrong direction," Bumgarner said. "I was just struggling making pitches today."

Crawford started the seventh with a homer, then after the next two batters went silently, Pablo Sandoval singled and Hector Sanchez roped a double down the left-field line which put San Francisco back on top, 5-4.

It was a 5-5 deadlock in the home half, as Christian Yelich worked a leadoff walk and scored when Solano followed with a double.

Game Notes

Marlins hurler Tom Koehler allowed seven hits and three runs with four walks and as many strikeouts over five-plus innings, while Bumgarner worked five full frames and surrendered four runs on five hits while walking four ...Coming into Sunday, Bumgarner has fashioned a 1.80 ERA in his past 11 starts since June 14, the third-lowest mark in the majors behind Clayton Kershaw and David Price ... Both teams are in action on Monday, as the Marlins host the Dodgers for four games and the Giants welcome the Red Sox for a three-game interleague set.