It was Pagan's first game back from the disabled list after a left hamstring injury sidelined him for 82 games.
"All that work we put in, all these weeks, it paid off," Pagan said. "I've been waiting for this moment for so long. I'm so happy to be back with the guys and help them any way I can."
Tim Lincecum pitched six spotless innings and third baseman Pablo Sandoval saved San Francisco with a diving play behind the bag. Three relievers closed it out for the Giants, who handed Randall Delgado a hard-luck loss and won for the 10th time in their last 12 games at Chase Field.
Pagan's injury came after he galloped around the bases for a game-ending, inside-the-park homer in May. He was reinstated from the 60-day disabled list before Friday's game.
"Good to have him back," Giants manager Bruce Bochy said. "It was a lift for the club. Although we got shut down with the bats, we did something we haven't done a lot of and that's get an early run."
Arizona loaded the bases against Lincecum in the sixth, and A.J. Pollock hit a sharp grounder past third. Sandoval had it played just right, though. He backhanded the ball as he hit the ground, got to his feet and threw to first for the third out.
"That was a huge play. I got the contact I wanted out of that," Lincecum said. "It was just a well-placed ball and Pablo managed to be there and made a great, great play."
Lincecum (8-13) allowed six hits and two walks while striking out two.
Romo has a 20-inning scoreless streak at Chase Field, and his 23 consecutive scoreless appearances there mark the longest such streak for any visiting pitcher at any ballpark dating to 1921, according to STATS.
Delgado (4-5) gave up only three hits over seven innings.
"He threw like Randall can throw. Great control, had them off balance and his location was pretty (darn) good," Arizona manager Kirk Gibson said. "He certainly pitched good enough to win. You've got to win them."
The Diamondbacks loaded the bases on two hits and a walk in the sixth, the only inning in which Lincecum got in trouble. But he struck out Miguel Montero for the second out before Sandoval's defensive gem.
"With what was on the line, bases loaded, that gets down the line and you're looking at a crooked number," Bochy said. "That's what defense can do for you. It can win ballgames, and that's what's gotten away from us at times."
The second-place Diamondbacks fell 10 1/2 games behind the Los Angeles Dodgers in the NL West.
"Panda made a good play on Pollock," Gibson said. "If you want to win those games you have to have better at-bats. That's all there is to it."
Three days after designating OF Jason Kubel for assignment, the Diamondbacks traded him to Cleveland for a player to be named or cash. ... The Diamondbacks will hold their second annual alumni game following Saturday night's game against the Giants. Players returning include Luis Gonzalez, Erubiel Durazo, Reggie Sanders, Mark Grace, Greg Swindell and Brandon Webb. ... To make room for Pagan, the Giants optioned OF Francisco Peguero to Triple-A Fresno and transferred OF Andres Torres from the 15-day disabled list to the 60-day DL. ... Play was held up briefly so groundskeepers could work on the mound before Lincecum delivered a pitch in the sixth.