PITTSBURGH -- The last-place Pittsburgh Pirates had plenty of fight left after sitting out their longest rain delay of the season at home.
The Pirates completed a three-game sweep of San Francisco and won their season-high fifth straight overall.
"It's a tremendous series to sweep and a lot of people participated," manager Jim Tracy said. "We're doing a lot of the things you need to do to in order to be a good ballclub."
The game was delayed 2 hours, 5 minutes by a strong storm that came through Pittsburgh with one out in the top of the seventh and the game scoreless.
Todd Linden, making only his third start of the season and first in left field, drove a 1-2 pitch from Pirates reliever Matt Capps into the seats above the right-field wall leading off the eighth for the game's first run. It was Linden's first home run since Aug. 31, 2005.
But Jose Castillo led off the bottom half of the ninth with a homer and Hernandez won it in the 10th.
"That's just the way things are going right now," Giants manager Felipe Alou said. "Blown saves and not hitting, you put that together, that doesn't add up to wins. That's a losing combination."
Hernandez and Wilson each had three hits and Castillo two for the Pirates, who are in last place in the NL Central but have won four of five series since the All-Star break.
John Grabow (3-1) got the last out of the 10th to get the win.
Castillo's ninth-inning homer off Giants closer Armando Benitez was his 12th of the season and first since June 15 -- a span of 180 at-bats.
"I feel good because it worked out for my team and it worked out for me," Castillo said.
Benitez has blown his last three save opportunities after converting his previous seven chances.
"The ball was in a good location and he hit it out," Benitez said. "He did a good job.
"It's not about confidence, it's about you trusting your pitches. Sometimes you throw good pitches and guys hit it."
Shea Hillenbrand was 2-for-4 for the Giants, who have not had a losing streak this long since the 2003 season. The seven losses have come by a combined 10 runs.
"It's tough. We need to figure out what's going on," starting pitcher Matt Morris said. "Not much is going right. We have to just go out and play better baseball. It's not like we played poorly, it's just our timing is off."
Hernandez's third hit was a line drive down the left-field line off Steve Kline (2-3) with Wilson on second base. Hernandez, who had only 89 at-bats this season coming into the game, had struck out in the eighth in a similar situation and Pirates down a run.
"I've just been on the bench watching the guys playing and then I get the chance to play and to do what I did today feels great," Hernandez said. "They've been playing me everywhere. They are giving me chances."
The weather appeared to be the only thing that could stop the starting pitchers, who were cruising through a fast-moving, scoreless game before the rain.
The Pirates' Zach Duke had thrown only 63 pitches when his game ended, while Morris threw 93.
Duke allowed only four hits in his 6 1/3 innings, and Pittsburgh managed just six hits off Morris through six innings. The starters combined to strike out only three batters -- all by Morris.
"I was controlling the ball everywhere I wanted to," said Duke, adding it was his best start since a shutout of the Chicago Cubs on May 2. "I was changing speeds. This was a very positive outing. It was just a trust in my pitches and focusing on the individual pitches to get the job done."
- It was the longest rain delay of the season at PNC Park. The start of the June 2 game against San Diego was delayed by an even 2 hours.
- The Pirates have had seven home games delayed for a total of 7 hours and 28 minutes.
- Barry Bonds was given a routine day off by the Giants, but he was intentionally walked when he pinch hit for Benitez in the 10th.