SAN FRANCISCO -- Travis Ishikawa lifted the San Francisco Giants' tattered spirits with one swing.
Ishikawa hit a tiebreaking three-run homer in the eighth inning after scoring the tying run in the seventh on a wild pitch and the Giants held off a rally to beat the Arizona Diamondbacks 5-4 on Tuesday night.
Juan Uribe hit a solo homer in the second for San Francisco, which bounced back from a heartbreaking 14-inning loss at Colorado on Monday night in which Ryan Spilborghs hit a game-ending grand slam.
"Ishi, it was his show tonight. What a job he did," manager Bruce Bochy said. "You have a game like last night, a gut-wrenching game ... you look at today and you have to be proud of them. You have to bounce back and be resilient. No getting around it, that's a big win for us."
The Giants snapped a three-game losing streak and remained four games behind Colorado in the NL wild card.
Ishikawa had one extra-base hit in his previous 70 at-bats -- going a stretch of 31 games without one -- before his double in the seventh. He connected off Jon Rauch (2-2) for his ninth homer, the biggest yet of his young major league career.
"I don't think I've ever hit a bigger home run than that late in the game to give us a lead," Ishikawa said. "We can't dwell on the last road trip, the last series. Everyone came in today and did a good job putting that behind us."
Jeremy Affeldt (1-1) pitched the eighth for the win and Sergio Romo recorded the final out for his second save in as many chances.
Brian Wilson, on the mound one night after throwing 41 pitches, retired the first two batters in the ninth before allowing a single to Augie Ojeda then walking pinch-hitter Rusty Ryal and Stephen Drew to load the bases. Ryan Roberts followed with a two-run single and Romo relieved and got Chad Tracy to ground out.
"It's huge for our team. It picks us back up," Romo said. "It's going to lift our spirits big time."
San Francisco returned from a tough 5-6 trip in which the Giants led all four games at Coors Field but lost the final three. They lost 6-4 in 4 hours, 57 minutes Monday night after scoring three runs in the top of the 14th -- and the team landed in San Francisco at 3 a.m.
Ishikawa scored the tying run in the seventh on Dan Haren's third wild pitch of the game.
Bob Howry walked Roberts on five pitches to start the eighth, and after starting 2-0 against Tracy, Bochy quickly to turned to Affeldt.
The Diamondbacks lost for the eighth time in nine games after snapping a season-long seven-game losing streak Sunday in a 7-5 win at Houston.
"We didn't quit and we made it interesting off their closer," Arizona manager A.J. Hinch said. "We just couldn't come through at the very end. It was an exciting game. It's unfortunate that we lose it because we battled back, we had the lead and they delivered the tough blow with the three-run home run."
Arizona scored twice in the fifth to take the lead, including getting an unearned run after Ojeda reached on Eli Whiteside's catcher's interference. Ojeda still made contact and hit a fly ball to right field, but got to take first.
Whiteside helped save a run in the sixth. Gerardo Parra drew a two-out walk, then was thrown out at home on Alex Romero's double. Whiteside blocked the collision and Parra didn't attempt to slide.
Slugger Pablo Sandoval didn't start for the Giants because of a bruised right calf but pinch-hit in the seventh. He drew an intentional walk after the wild pitch that allowed Ishikawa to score. Pitcher Barry Zito entered as a pinch-runner, the third time in two games the Giants have inserted a pitcher to run.
The night began as a pitcher's duel featuring 12-game winners Matt Cain and Haren.
Haren struck out six and walked one in seven innings. Cain, the All-Star right-hander, received his third straight no-decision and is winless in six starts since a victory at Coors Field on July 24.
Copyright 2015 Associated Press. All rights reserved. This material may not be published, broadcast, rewritten, or redistributed.