SAN FRANCISCO -- Jonathan Sanchez gave the San Francisco Giants exactly what they needed Friday night.
Sanchez pitched into the seventh inning, Andres Torres homered and San Francisco beat the Arizona Diamondbacks 2-0 to end a six-game losing streak.
"Sometimes when you get into a streak like we were in, that is what it takes, the guy on the mound to pitch a great ballgame," manager Bruce Bochy said. "That is what Sanchy did for us."
Sanchez (1-1) allowed just two hits and struck out four in 6 2/3 innings to pin another difficult loss on Dan Haren. Sanchez walked four but didn't allow a runner past second base.
"All the pitches were doing what they had to do and I was just getting ahead of hitters," he said. "Sometimes I have it, sometimes I don't. I felt strong. I was feeling good. I went out there and did what I had to do."
Jeremy Affeldt, Bob Howry and Brian Wilson finished the three-hitter. Wilson recorded the final four outs for his first save of the season.
Haren (0-3) struck out six and allowed just one run in six sharp innings, but remains winless in three starts. The Diamondbacks have been shut out twice this season, both times with the hard-luck right-hander on the mound.
"I made a few mistakes throughout the way but there's not much more I could do," Haren said. "I go out and I do my best to stay confident every time out but it's tough. We're not playing well as a team and I'm 0-3. I'm not happy about it and I'm not going to sugarcoat it and tell you guys, 'Hey oh well we'll get 'em next time.' I'm not happy. I'm 0-3. It doesn't feel good."
Bengie Molina singled in Pablo Sandoval with two outs in the fourth and Torres hit his second career home run leading off the eighth for the Giants, who returned to AT&T Park after going 0-6 on their first road trip of the year.
San Francisco struggled offensively during the trip and didn't exactly break out of the hitting slump against the Diamondbacks.
Sanchez, who was knocked out of his previous start after giving up five runs in 4 2/3 innings against San Diego, allowed a double to Felipe Lopez leading off the game and a two-out double to Justin Upton in the seventh but that was all.
He struck out Chris Young with two on to get out of the first, then kept the Diamondbacks off balance with a fastball that still registered 90 mph in the seventh. He walked Chris Snyder after Upton's double but Affeldt got Tony Clark to fly out to end the inning.
"[Haren's] a pretty good pitcher and I didn't think we were going to score a lot of runs and that's what happened," Sanchez said. "He did his job and pitched pretty good too."
Haren allowed just one hit through three innings and faced the minimum 11 batters before Sandoval hit a two-out double down the right-field line in the fourth.
Molina followed with a sharp single to left to drive in Sandoval and Fred Lewis singled to right to put runners at the corners before Haren struck out Travis Ishikawa to end the threat.
Torres hit a drive off Scott Schoeneweis leading off the eighth for his first homer in the majors since Sept. 14, 2003.
Affeldt and Howry kept the Diamondbacks quiet until Wilson took over with a runner at third in the eighth. The closer struck out Mark Reynolds to end the inning but walked Young leading off the ninth. Eric Byrnes then grounded into a 1-4-3 double play before Wilson struck out Upton to seal the win.
"It seems when we did hit balls hard it was right at people, but certainly not enough to put us in a position to win a game," Arizona manager Bob Melvin said. "Just not enough good at-bats to win a game."
The Giants recorded their first shutout since a 1-0 win over the Dodgers on Sept. 21, 2008. ... Arizona SS Stephen Drew left in the fifth inning with tightness in his left hamstring and is day to day. ... San Francisco's Tim Lincecum was seen by a doctor after being bothered by an upset stomach recently but nothing came out of it and the reigning NL Cy Young Award winner is expected to make his scheduled start Saturday. ... RHP Joe Martinez rejoined his San Francisco teammates for the first time since getting hit in the head by Mike Cameron's line drive on April 9. Martinez, who suffered a concussion and three hairline fractures in his skull, has a black eye and cannot begin his rehab for at least a month but is otherwise fine. "I guess I'm lucky," Martinez said. "I'm not dizzy. I don't have any nausea. My vision's good so I'm feeling good."