SAN FRANCISCO — Marco Scutaro and Brandon Belt hit consecutive RBI singles in the eighth inning to help the San Francisco Giants edge the Colorado Rockies 4-3 on Wednesday.

The Giants loaded the bases with one out against Matt Belisle (5-7), and Scutaro followed with a tying single into right field. Belt's hit drove in Angel Pagan and gave San Francisco a 4-3 lead.

Guillermo Moscoso (2-2) pitched two scoreless innings for the victory, securing the first winning homestand for the Giants since May 20-26. Santiago Casilla finished for his second save.

Nolan Arenado had two hits and two RBIs for the Rockies, who have lost five of six. Michael Cuddyer added three hits and went 7 for 13 in the series.

Pablo Sandoval and Hunter Pence each drove in a run for San Francisco, which has won three of four.

Giants right-hander Yusmeiro Petit struck out seven in 5 2-3 innings in his first start since he almost threw a perfect game against Arizona before settling for a one-hitter. He gave up three runs and six hits with two walks.

Petit retired the first 10 batters he faced before walking Corey Dickerson in the fourth. Dickerson raced over to third on Cuddyer's base hit and scored on Arenado's single, tying it at 1.

Colorado added two more in the sixth on RBI singles by Arenado and Charlie Culberson, making it 3-1.

Rockies starter Juan Nicasio was in line for the win before San Francisco rallied. He held the Giants to one run and five hits in five innings.

The Giants left the bases loaded twice, once with two outs in the second and once with one out in the fifth.

San Francisco pulled within one in the seventh, taking advantage of a bout of wildness from Josh Outman. The lefty walked the bases loaded with no outs, and Pence hit a sacrifice fly against Adam Ottavino.

The Giants had a chance for more, but Sandoval and Hector Sanchez grounded out to end the inning.

NOTES: Giants LHP Jeremy Affeldt will be reinstated from the disabled list in time for Thursday's game in Los Angeles. ... Scutaro was scheduled for a day off but convinced manager Bruce Bochy to play him. ... RHP Matt Cain (8-9, 4.37 ERA) will start for the Giants in the series opener against the Dodgers on Thursday. He's 5-1 against them in his last 12 starts. ... Petit set down 38 of 39 batters before walking Dickerson. ... The Rockies will start RHP Tyler Chatwood (7-4, 3.17 ERA) in their series opener in Arizona on Thursday. ... Nicasio has allowed three earned runs in his last 22 innings against the Giants. ... Belisle needed 36 pitches to get through the eighth, the most by any Rockies reliever in an inning this season. ... The Giants left 13 runners on base. They've stranded 13 or more five times this year.