The loss snapped a three-game winning streak for the Pirates, who had won five of their previous six.
Chris Burke started the winning rally by drawing a one-out walk off Matt Capps (0-1) and stole second with two outs before David Eckstein walked. That brought up Giles, who singled to right field to bring in Burke.
Edwin Moreno (1-2) allowed one hit in two innings for his first big league win.
Kevin Correia was trying for his first win with his hometown Padres but couldn't hold a 3-1 lead in the sixth. He walked Adam LaRoche leading off the inning and Eric Hinske reached on a double when Giles couldn't hang onto his flyball after leaping against the right-field wall. Cla Meredith came on and allowed Brandon Moss' RBI groundout and Andy LaRoche's RBI single to center.
Jason Jaramillo singled and stole second before Nyjer Morgan was intentionally walked to load the bases for Jack Wilson, who was hitless in his previous three at-bats. Wilson struck out to end the threat, tossing his bat and helmet in disgust.
Correia allowed three runs and three hits.
Pirates starter Ian Snell gave himself a 1-0 lead when he hit an RBI single to center with two outs in the second.
It didn't last long, though, as Adrian Gonzalez homered to center on Snell's first pitch in the bottom half for his sixth of the season.
San Diego added on with four more extra-base hits in the next two innings. Luis Rodriguez doubled leading off the third and scored on David Eckstein's triple into the left-field corner. Chase Headley opened the fourth with a double into the right-field corner and scored on Nick Hundley's double to left-center.
Snell allowed three runs and six hits in five innings. He had two hits and made a nifty catch of Jody Gerut's line drive to end the fourth with the bases loaded.
Notes:@ Pirates CF Nate McLouth was scratched with an injured right oblique. ... Gonzalez, San Diego's only All-Star last year, took Moss' liner off the heel of his glove in the 10th. ... San Diego OF Cliff Floyd, who's been on the disabled list since opening day with a strained right shoulder, had an MRI and a shot on Thursday. The team said it will monitor Floyd for a week. ... San Diego RHP Cha Seung Baek, on the DL since just before the season started, threw 45 pitches in a bullpen session and appears close to starting a rehab assignment.