In a game that lasted more than four hours, the Phillies came out on top thanks to a hustle play by Chase Utley.
With two men on and two outs in the 13th, Ben Revere grounded to second baseman Logan Forsythe, who booted the ball. Utley hesitated only briefly as he rounded third and headed for home.
Forysthe's throw got away from catcher Nick Hundley, allowing Domonic Brown to score as well to give the Phillies a 7-5 advantage.
And in the bottom of the 13th, Jonathan Papelbon got a measure of redemption as he earned his 15th save of the season after blowing four save opportunities in a seven-game stretch.
Papelbon's save capped off an impressive outing for the Phillies bullpen, who pitched seven scoreless innings in relief of Cole Hamels.
Hamels struggled again, giving up five runs in six innings of work, and it looked like he would fall to 2-12 on the season until Delmon Young tied the game with a two-run home run in the eighth inning.
Hamels' performance is still disconcerting. After 16 starts he is still struggling with his command and leaving too many balls out over the plate. He gave up a home run to Chris Denorfia in the fifth inning on a pitch that he grooved right down the middle.
Still, Phillies fans can take heart from the performance of the bullpen, especially the newly recalled Phillipe Aumont who pitched a scoreless seventh and eighth innings.
Though he walked the bases loaded in the seventh, Aumont was able to work out of the jam with no harm done, then came back and got a 1-2-3 eighth.
Jake Diekman, Joe Savery and Papelbon combined to finish the job and help the Phillies (38-41) take two of three from the Padres (39-40).
The Phillies' west coast swing continues with four games against the Los Angeles Dodgers beginning Thursday night.
Hopefully the team can take the positives from Wednesday's dramatic victory and carry the momentum straight through the rest of this road trip.