Headley gave the Padres the early lead with his 29th home run of the season and 21st of the second half, driving a 2-2 changeup from Giants starter Ryan Vogelsong out of the ballpark and into the waters of McCovey Cove.
The Giants came around to tie the game at 1 after Kelly followed a walk to Brandon Belt with back-to-back singles by Gregor Blanco and Brandon Crawford. Kelly was lifted in the fifth after striking out Hunter Pence, which came after Buster Posey's go-ahead RBI single that scored Marco Scutaro.
The Padres had a chance to even the score in the sixth when Yasmani Grandal sent a Vogelsong pitch into the left-field corner with Headley on first, but quick, accurate throws from Gregor Blanco in left and Brandon Crawford at short led to Headley getting tagged out at home by Posey.
"To me, that was the turning point in the game," Giants manager Bruce Bochy said. "Those types of plays win ballgames for you."
"I felt like I was running in quicksand. You can see the play developing in front of you," Headley said. "I was on first base and then I see the ball go down in the corner and I'm running to third. Coming around third, you can kind of sense the urgency. You have to try to make a play right there. I thought it was the right play; they just executed. They had a great relay."
Headley said he was mindful of the fact that it was Posey behind the plate given the season-ending injury he sustained last year in a home-plate collision with Florida's Scott Cousins.
"That's a tough situation because you want to play the game hard and you want to play it the right way," Headley said. "It's terribly unfortunate what happened to him last year, but I think you have to keep playing the right way. You obviously don't go out of your way to intentionally hurt somebody, but if it's the right play and you don't have another choice, then I think you have to. Hopefully he's in a position where it won't happen to him again."
In his fifth career start, Kelly still managed to hold the Giants' offense mostly at bay, escaping a third-inning jam by getting Posey to pop out with the bases loaded.
"He hung in there without having his best control and command," Padres manager Bud Black said. "His stuff was fine; he was just missing a little bit too much pitch to pitch."
The Padres' bullpen was tagged for three runs in the sixth inning, including a towering two-run home run from Pablo Sandoval off Cory Burns.
Catcher Yasmani Grandal left the game in the seventh inning after taking a foul tip to the mask, replaced behind the plate by Ali Solis. Black said Grandal was evaluated after the game and that he would be back in the lineup Saturday.
"I've been hit before; it's nothing new," Grandal said, adding that he'll be wearing a hockey-style catcher's mask Saturday. "It comes with the job."