David Peralta and Gerardo Parra each added two hits for the Diamondbacks, who won their fourth in six games.
Marco Scutaro went hitless in two at-bats with a walk in his season debut for the Giants, who were shut out for the fifth time in 13 games.
Miley (5-6) allowed four hits and won his second straight start for the first time since early April. He has given up three runs over his past 22 2/3 innings.
Brad Ziegler worked the eighth and Addison Reed pitched the ninth for his 21st save in 26 chances.
Ryan Vogelsong (5-7) gave up two runs and six hits in 6 1/3 innings.
Vogelsong has lost his last four starts despite a 2.19 ERA over that span. The Giants have been shut out in each of his last three starts and given him one run of support in his last 24 2/3 innings.
Scutaro, a postseason star for the Giants in their run to the 2012 championship, received a standing ovation when he came to the plate for his first at-bat of the season. He drew a walk.
Scutaro has missed the first half of the year because of a back problem.
Miley permitted one hitter - Brandon Belt, who singled and walked twice - to reach third base and that came with two outs in the seventh.
Miley gave up one leadoff hit, and then promptly picked off Gregor Blanco in the fifth.
Hill homered with one out in the fourth. He hit a leadoff double in the seventh and Parra's RBI single ended Vogelsong's day.
NOTES: The Diamondbacks pushed RHP Chase Anderson's scheduled start Sunday to five days after the All-Star break as a proactive move to reduce the possibility of fatigue as his workload increased. ''It will be good for him, give him time to recover physically and mentally,'' Arizona manager Kirk Gibson said. LHP Vidal Nuno will make Sunday's start instead. Recently acquired from the New York Yankees, Nuno threw seven shutout innings in his first appearance with the Diamondbacks on Tuesday. ... Parra drove in just his second run since June 7. He entered the game hitting .180 (20 for 111) since then. ... Arizona 1B Paul Goldschmidt singled in the first inning and has reached base safely in a career-high 32 straight game, the longest string by a Diamondbacks player since Orlando Hudson went 33 straight in 2007. ... LHP Madison Bumgarner (9-7, 3.36) pitches for the Giants on Sunday. He's on a three-game losing streak after giving up a season-high six runs in his last start. . Giants SS Brandon Crawford was given the day off. . Prado went hitless in four at bats and had his 10-game hitting streak end.