The Giants held a 5-4 lead late in the game but the Marlins scored single runs in the the seventh and eighth innings to pull out the victory.
Miami forged a 5-5 tie in the seventh when Christian Yelich drew a lead-off walk from Guillermo Moscoso and Donovan Solano followed by belting a pitch into the left-center gap for an RBI double.
Then in the next inning, Ed Lucas led off with a single against Sandy Rosario (3-1) and one out later Mathis (2-for-3, solo homer) delivered a clutch, run-scoring two-bagger for the decisive tally.
Chad Qualls (4-1) tossed 1 1/3 scoreless innings to get the win and Steve Cishek notched his 27th save as Miami avoided a three-game sweep.
2014: The Year in Music [PHOTOS]