PHOENIX -- Chad Gaudin's stomach was upset, but his arm was just fine Sunday.
Gaudin scattered five hits over six innings, and Marco Scutaro and Brandon Belt homered as the San Francisco Giants beat the Arizona Diamondbacks 6-2 Sunday afternoon.
"I thought maybe it was nerves in the beginning," Gaudin said of his stomach ailment. "It kinda lingered the whole game, so I just had to battle that."
Buster Posey, Joaquin Arias and Juan Perez added RBI singles for the Giants, who won the final two games of the three-game series to pull within 1 1/2 games of Arizona in the NL West.
San Francisco largely has treaded water since falling out of first place on May 27, going 5-7. The Giants scored a total of 39 runs in the 12 games, 16 of them the past two days.
"The boys did well, bouncing off a tough loss (Friday) and taking the next two," Giants manager Bruce Bochy said. "The bats, it's good to see them come to life. We played well here the last two nights. We need to pick it up in our overall play."
Gaudin (2-1), making his second start after beginning the season as San Francisco's long reliever, allowed two runs, struck out seven and walked one. He threw 84 pitches, 54 for strikes.
"It makes for a better game," Gaudin said of throwing strikes. "It enables me to expand when I can. You're letting the hitter know that you're not going to pitch around him. You're going to go right at him."
Diamondbacks starter Tyler Skaggs (1-1) struggled from the outset but managed to go five-plus innings, giving up five runs on eight hits and three walks with four strikeouts.
"It's a tough game," Skaggs said. "It was just one of those days you keep the ball up and you're going to get hit. Baseball's a humbling game. You can't go out there and dominate every time, even though you'd like to."
Skaggs, making his third start of the season and ninth of his career, faced six batters before finally recording his first out of the game.
Andres Torres, Scutaro and Posey started the game with consecutive singles, the last scoring Torres for a 1-0 lead.
Skaggs walked Hunter Pence to load the bases, and Arias, subbing for the injured Pablo Sandoval, singled to center to make it 2-0.
Pence doubled to lead off the third, his third extra-base hit in six at-bats, and scored on Perez's first career hit to extend the Giants' lead to 3-0.
Scutaro added a solo home run off the netting on the inside of the left field foul pole with one out in the fourth for a 4-0 lead.
"He didn't have any good command," Diamondbacks manager Kirk Gibson said of Skaggs. "He got behind a lot of guys."
The Diamondbacks, who managed only one hit off Gaudin over the first three innings, broke through in the fourth.
Miguel Montero hit a one-out single, went to second on Jason Kubel's two-out single to right and scored on a single by A.J. Pollock.
Kubel then came home on a balk called by third base umpire Greg Gibson when Gaudin failed to come to a complete stop, pulling Arizona to within 4-2.
"Their guy was just getting ahead and pounding strikes in the zone," Gibson said.
Belt answered in the top of the fifth, driving a fastball from Skaggs to right for his seventh home run and first since May 20 for a 5-2 lead.
"He's swung it well here," Bochy said. "He's somewhat notorious for a slow start and picking it up in the second half, and we need him."
Torres' eighth-inning sacrifice fly completed the scoring.
Four Giants relievers combined to throw three scoreless innings, giving up just one hit.
NOTES: An MRI on Sandoval's left foot Sunday revealed no new damage, but Sandoval said the strained muscle was "sore. I can't play on it right now." Sandoval aggravated the lingering foot injury in his first at-bat Saturday night. "That was stupid," Sandoval said of playing after taking three of the prior six days off. "I don't know what I was thinking." Bochy said a decision on Sandoval's roster status might be made on the flight to Pittsburgh and that a trip to the disabled list is possible. "We need to get this calmed down," Bochy said. ... Gaudin was making his second straight start after being used strictly in relief since 2009. ... Skaggs has allowed four home runs in 16 2/3 innings. ... In addition to recording his first career hit, Perez ran full speed into the padded right field wall as he tracked down and caught a long fly ball hit by Paul Goldschmidt in the first inning.