Jeff Mathis hit an early home run then lined a tiebreaking double in the eighth inning that bounced off Giants center fielder Andres Torres and sent the Miami Marlins over San Francisco Giants 6-5 Sunday.

It was 5-all in a back-and-forth game when Ed Lucas led off the eighth with a single against Sandy Rosario (3-1). With one out Mathis hit a liner to left-center and the ball dropped in front of Torres' dive and caromed off him.

Chad Qualls (4-1) pitched 1 1-3 scoreless innings and Steve Cishek worked the ninth for his 27th save in 29 chances.

Hector Sanchez singled with one out in the ninth before Buster Posey grounded into a game-ending double play.

Hunter Pence homered and drove in three runs Brandon Crawford also hit a home run and Gregor Blanco had three hits for the Giants.

Miami starter Tom Koehler allowed three runs and seven hits in five innings.

Crawford led off the seventh a home run against Mike Dunn tying it at 4. Sanchez hit a go-ahead double later in the inning that put the Giants ahead.