San Francisco looked headed toward a three-game sweep of Philadelphia, as it was ahead by a 4-1 score with ace Tim Lincecum on the mound entering the top of the ninth.
But after Lincecum walked Shane Victorino with one out, Giants manager Bruce Bochy elected to remove his starter, and the game took on a completely different dimension, going from a duel between Lincecum and Cole Hamels to a game filled with bloop hits, close calls and wacky bounces.
Jayson Werth hit a three-run double in the ninth off Giants closer Brian Wilson to send the game to extras, while Ryan Howard finished 2-for-4 with a walk and a home run for the Phillies, who snapped a three-game slide.
Andres Torres went 2-for-6 and drove in three, including the game-tying run in the bottom of the 10th off Ryan Madson (1-0), who blew the save but ended up with the win.
Nate Schierholtz had a career-high five hits, walked and drove in a run in the bottom of the 11th, but the Giants fell one run short in losing for just the second time in their last six games. Sergio Romo (0-2) earned the loss for giving up the deciding runs.