SAN FRANCISCO -- Brandon McCarthy finally pitched well on the road.
McCarthy hadn't won away from Arizona since May 18 before putting together a dominant performance in San Francisco on Saturday night.
The right-hander allowed one run and six hits in eight innings as the Diamondbacks beat the Giants 2-1. He had been 0-4 with an 11.40 ERA in his previous four road starts, but was able to throw strikes against San Francisco.
McCarty (4-9) struck out six and walked one. He threw 70 strikes in 99 pitches.
"For me I have to have command and if I am not using everything and using it to both sides of the plate it becomes a much easier job for teams to hit me," McCarthy said.
McCarthy was on the 15-day disabled list from May 31 to August 2 with a right shoulder inflammation and had been struggling with his mechanics most of the season until recently.
"Once I was able to kind of fix what I needed to mechanically everything has gone back into place the way I hoped it would," McCarthy said. "It's less thinking and just kind of being able to execute."
McCarthy has now walked three batters or less in 76 consecutive starts, the third-longest active streak in baseball.
Brad Ziegler pitched a scoreless ninth for his ninth save in 11 chances.
Matt Cain (8-9) gave up two runs and eight hits in 6 1-3 innings. He struck out three and walked four.
"I didn't make some pitches when I needed too and it ended up costing us," Cain said.
He was activated from the 15-day disabled list prior to the game after missing 14 games with a contusion on his right forearm. Coming into the game Cain had just one win in his last nine starts at home, going 1-5 with a 5.36 era over that stretch.
"Coming off the DL, it's been a while since he's pitched and he did a good job," Giants manager Bruce Bochy said of Cain. "He went into the seventh and gave up only two runs. He made a couple mistakes but he pitched well."
Paul Goldschmidt had three hits, including a triple.
"I just got some good pitches to hit," Goldschmidt said. "If you ask Cain he probably would say they were a few mistakes."
Arizona broke a 1-1 tie in the fifth inning when Goldschmidt drove in Adam Eaton with a triple to deep right centerfield. Eaton had walked.
The Giants got to McCarthy in the third inning as Brandon Crawford led off with a single and was bunted over to second by Cain. After a fielder's choice moved Crawford to third he scored on Marco Scutaro's single.
With San Francisco leading 1-0, Arizona got the run back as Gerardo Parra hit a two-out single to right-field to drive in Goldschmidt, who led off the inning with a single.
The Diamondbacks ended the first, third and eighth innings by getting thrown out on the bases.
In the first Goldschmidt singled with two outs but was caught attempting to steal second. In the third A.J. Pollock singled with one out but was doubled up on a fly out to Giants centerfielder Angel Pagan.
Pollock was stealing second on the play and didn't realize that the ball was a fly-out and was barely beaten by the throw back to first. In the eighth Will Nieves was thrown out at the plate trying to score from first on a double to left centerfield by Parra with two outs. Pagan hit cutoff man Crawford who relayed the throw to Giants catcher Hector Sanchez for the tag out.
"We were just trying to be aggressive on the base paths," Goldschmidt said. "That was an unbelievable throw to the plate by Crawford."
NOTES: Sunday's game features starting pitchers Wade Miley (9-10, 3.78) for Arizona versus Madison Bumgarner (11-9, 2.91) for the Giants. ... McCarthy had not won on the road since May 18 at Miami and was 0-4 with an 11.40 era in his previous four road starts. ... Arizona's Chris Owings registered his first Major League hit in the sixth, a single off Cain. Owings added a second single in the ninth inning and had his first Major League stolen base later in the inning. ... Pagan had two throwing assists in the game.