SAN FRANCISCO (AP) Kirk Gibson asked Ian Kennedy if he could keep going, and Arizona's ace delivered with a career-high 122 pitches.
Good timing, too. Closer JJ Putz had slept wrong and arrived with a stiff neck, which he tried to loosen up in the fourth inning to no avail.
Paul Goldschmidt hit a go-ahead homer in the sixth inning to help Kennedy snap a five-start losing streak, and the Diamondbacks avoided a three-game sweep with a 4-1 victory over the San Francisco Giants on Wednesday night.
Kennedy (4-5) outdueled Tim Lincecum (2-6) in a matchup of struggling aces to win for the first time in seven starts since beating the Braves on April 22.
''It's been a while since I've been standing in that line with the high-fives at the end of the game,'' said Kennedy, who made a minor tweak to his delivery to get more on top of the ball. ''To beat someone like the Giants or like Tim throwing tonight, it means a lot.''
Goldschmidt crushed a 1-0 slider into the left field bleachers for his fourth home run of the year, 12th of his career and fourth off Lincecum in 13 at-bats - most by any opponent against the two-time NL Cy Young Award winner. Goldschmidt also added an RBI single in the eighth for an insurance run and Ryan Roberts also singled in a run.
Lincecum insists he will adjust next time against Goldschmidt.
''I'm not hoping. I'm going to figure it out,'' he said.
Melky Cabrera singled in the eighth to finish his marvelous May with 51 hits, matching Randy Winn's San Francisco record for most hits in a month set in September 2005. The last player in baseball with 50 or more hits in a month was Carl Crawford, with 50 for Tampa Bay in August 2007. Cabrera smiled as he received a standing ovation from those still left in the sellout crowd of 41,328.
Lincecum lost his third straight outing and his winless stretch reached six straight starts since the right-hander beat San Diego on April 28. He went 0-4 in May for his first month without a victory since a career-worst five-start losing streak in August 2010.
Lincecum bounced back that year to become the winning pitcher in the Game 5 World Series clincher at Texas.
This time, the Giants didn't give him enough support with more missed chances. San Francisco had its three-game winning streak snapped as Arizona ended a four-game skid in the rivalry.
Kennedy extended his winning streak against the Giants to five straight starts, and the D-backs are 6-0 in his last six outings versus San Francisco. A 21-game winner last season, Kennedy had been 9-0 over his previous 12 starts before this recent funk.
He struck out seven and walked two in 7 2-3 innings to beat Lincecum for the third straight time. Kennedy gave up one run on five hits and has allowed just four runs in 21 1-3 innings in those three games facing Lincecum.
David Hernandez recorded the final four outs for his first save in four opportunities in place of Putz.
The Diamondbacks took a 1-0 lead in the second on right fielder Gregor Blanco's fielding error. He caught Roberts' fly, then bobbled the ball and dropped it while trying to move it into his throwing hand in order to fire to home and prevent a sacrifice fly. Miguel Montero held up but wound up scoring on the misplay.
San Francisco tied it in the fourth on Ryan Theriot's RBI single following a leadoff triple by Blanco.
Lincecum lasted six innings for just the second time in his last six starts, but matched his season high with five walks to go with six strikeouts. He allowed two runs - one earned - on four hits in seven innings.
''It was big on a personal level because I haven't been going deep into games. I still took the L,'' Lincecum said. ''Outside of the walks, I thought it was better altogether. The crucial inning was the home run. That's the one pitch I'm thinkng about.''
Gibson caught Goldschmidt closing his eyes to visualize before the at-bat.
''I said, go out there, live it up and show me what you're visualizing,'' Gibson said. ''Boom!''
The Giants, who dropped the first four meetings of the year with the defending division champion D-backs, have failed to record a series sweep in four chances this season.
Angel Pagan extended his home hitting streak to 24 games with a leadoff single in the seventh.
NOTES: Kennedy has allowed three or fewer runs in 11 of his 12 starts vs. San Francisco. ... Giants RHP reliever Sergio Romo wasn't available because of an unstable or ''subluxed'' right kneecap. He was injured doing his pregame warmup routine Monday. ... Arizona LF Jason Kubel returned to Phoenix on Wednesday morning just in time - 10 minutes before his wife, Blake, delivered their second child. Heidi Evelyn, 7 pounds, 7 ounces, joins big brother, Owen. Gibson expects him to rejoin the team Friday at San Diego after a short stint on the paternity list. OF A.J. Pollock was recalled from Triple-A Reno to replace him. ... San Francisco 3B Pablo Sandoval said he expects team doctors to examine his surgically repaired left hand Thursday or Friday, and believes he could begin a rehab assignment as soon as Monday if all goes well. The switch-hitter is still not swinging right-handed. ... D-backs SS Stephen Drew, working back from a broken right ankle hurt last July, is scheduled to play back-to-back games at extended spring training Friday and Saturday and if all goes well he will report to Reno early next week to begin a rehab assignment. ... Arizona RHP Takashi Saito, who is on the 15-day DL with a strained right calf, threw live batting practice and is scheduled to pitch again Saturday before joining Reno on June 5.