Torres and Juan Uribe combined for seven hits and seven RBI in a wild game that saw the Marlins overcome a seven-run deficit in the late innings.
The Giants, however, loaded the bases in the 10th on one-out singles by Aaron Rowand, Edgar Renteria and Nate Schierholtz. Torres then hit the first pitch from losing pitcher Clay Hensley (1-4) to deep center, a shot that would have gone for extra bases had the Giants needed more than one run to win the game.
Torres also had a two-run homer in the sixth that gave San Francisco a 9-2 lead. Uribe delivered a two-run single during a four-run fourth and added a two-run triple in the third. Uribe then scored on a wild pitch.
Florida began its comeback with a five-run seventh, during which Donnie Murphy had a three-run homer and Dan Uggla had a two-run shot.
The Marlins stayed alive by tying it with two in the ninth off closer Brian Wilson. A ground out by Gaby Sanchez brought home Hanley Ramirez from third and Uggla tied it with a two-out ground-rule double.
Chris Ray (4-0) retired the side in order in the top of the 10th to get the win.
Celebrity Families of 2014 [PHOTOS]