PHOENIX -- Cody Ransom didn't look, Clayton Kershaw didn't have to and suddenly, Kirk Gibson didn't feel so bad anymore.
"Of course," the D-backs manager, who left Saturday's game due to an illness, said about feeling better. "It was a good game."
Trailing by a run in the seventh inning Sunday afternoon, Ransom, the D-backs' journeyman shortstop, hit a game-winning two-run homer off Kershaw, the Dodgers' left-handed ace, for a 4-3 victory at Chase Field, as the D-backs avoided a sweep and remained a half-game behind the Giants in the National League West.
"It worked out for me," Ransom said. "I wasn't sure if I was ever going to get a hit at this park, so it's nice to finally get one here and it happened to help us win a game. We lost a few games in a row, so it was big for us today."
After Kershaw kept the Arizona offense at bay for much of the game, Collin Cowgill hit a one-out single up the middle in the seventh, then Ransom connected with a 1-1 fastball and sent it over the left-field fence, bringing the 25,575 in attendance to their feet and Kershaw to a crouch on the mound.
"I got a lot of hittable pitches today, but I missed them," Ransom said. "He got that one out a little more out over the plate than the rest of them, and it didn't cut as much."
The hometown home run was the first of the Mesa native's stint with the D-backs.
"Hometown guy or not, any hit like that is a lot of fun," Ransom said. "But being at home, I'm sure I'll get some phone calls after the game."
Two innings later, he ended the game with his third backhanded play in the hole at shortstop of the day to retire Juan Rivera and pick up Ian Kennedy's 14th victory -- tied for first in the NL -- and J.J. Putz' 26th save of the season.
Ransom's all-around performance while filling in for Willie Bloomquist helped halt a three-game losing streak.
"We've talked about playing everybody on the team," Gibson said. "You can't expect them to do something like that if you throw them in there occasionally, but you still want to make sure they still feel a part and have their confidence.
"He played good at shortstop today and, obviously, the big blow there was the two-run homer, but that's kind of who we are."
Ransom's home run came an inning after Kennedy had relinquished a two-run lead in the sixth on run-scoring hits by Andre Ethier -- a game-tying double to score Aaron Miles -- and Rivera -- a single to score Ethier.
After retiring Jamey Carroll to open the sixth, the D-backs right-hander battled Miles for eight pitches, but ended up allowing a single.
"He's a battler up there," Kennedy said. "Him and Carroll. They take a lot of pitches and foul balls off with two strikes. They're just hard to strike out."
Kennedy allowed three runs on six hits over seven innings, while striking out three and walking one.
The only other blemish on his line was a solo home run by James Loney in the fifth inning.
"I just tried to throw a quality game," Kennedy said. "I made some pitches where I left some balls up and they got some hits off me, and I just tried to let my team pick me up today, and they really did."
Kennedy pitched at least six innings while allowing three runs or less for the sixth consecutive outing.
The D-backs took an early lead against Kershaw, who hadn't allowed an earned run to them this season entering the game, when Ryan Roberts walked on four pitches to lead off the first and Kelly Johnson followed with his 18th home run of the year.
It was the third home run Kershaw has allowed to a left-handed batter this season.
"It took me too long to adjust," Kershaw said. "You give up a four-pitch walk, you're going to give up runs. It's frustrating, but I did that in the last game, walked a guy on four pitches and gave up a run. Overall, I pitched alright. But the first inning kills you."
But he settled down from there and retired 16 of the next 18 batters before Cowgill's one-out single in the seventh.
He was pulled after giving up a pinch-hit double to Sean Burroughs and ended up allowing four runs on five hits over 6 1/3 innings, with seven strikeouts and three walks.
"The team battled back," said Kershaw. "They gave me a lead and I gave it back. No one to blame but me."
After David Hernandez worked a scoreless eighth inning, Putz delivered his first perfect save since coming off the disabled list on July 26.
"What it comes down to is we needed to take care of business," Kennedy said. "We try to avoid getting swept at our own place, and it's frustrating that we lost a series at our own place, but we have to take care of business."
Anthony Fenech is an associate reporter for MLB.com. This story was not subject to the approval of Major League Baseball or its clubs.