Gabriel Moreno scored on a wild pitch before Pham drove in Jordan Lawlar with a liner to left against rookie Daniel Palencia (5-1). Lawlar was hit by a pitch and advanced on Yan Gomes' passed ball before taking third on the wild pitch.
Kevin Ginkel (8-0) got three outs for the win and Paul Sewald worked the 10th for his 32nd save. Cody Bellinger hit a two-out RBI single, but Sewald got Dansby Swanson to foul out to the catcher.
The Diamondbacks (75-68) moved within one game of the Cubs (76-67) for the No. 2 slot in the NL wild-card standings.
Chicago has just four runs and 16 hits through the first three games of the four-game series.
Arizona loaded the bases after the first two batters were retired in the top of the ninth, but Adbert Alzolay retired Moreno on a grounder to shortstop.
Chicago also threatened in the ninth. Gomes hit a one-out drive off the wall in left, but he was cut down trying for second. Nick Madrigal doubled, but he was stranded when Mike Tauchman grounded out.
Justin Steele pitched seven innings of six-hit ball for the Cubs, dropping his ERA to a major league-best 2.49. The All-Star left-hander, one of the front-runners for the NL Cy Young Award, is 7-0 with a 2.48 ERA in his last 10 starts.
Merrill Kelly tossed 5 2/3 innings of one-run ball for Arizona. The right-hander allowed four hits, struck out six and walked five - matching his season high.
Kelly departed with the bases loaded, and Ryan Thompson escaped the jam by retiring Gomes on a fly ball to center.
Chicago jumped in front in the third, taking advantage of an embarrassing misplay by Arizona. With two out and Nico Hoerner aboard after a bunt single, Bellinger hit a high popup that landed in the infield near second - between rookie shortstop Lawlar and second baseman Ketel Marte.
A hustling Hoerner scored all the way from first, and then yelled in celebration as he made his way back to the dugout.
Arizona responded in the fifth when Corbin Carroll hit a leadoff single, stole second and advanced to third on Emmanuel Rivera's single. Carroll then came home on Moreno's grounder to third.
It was the first run allowed by Steele since Aug. 24, stopping a string of 21 consecutive scoreless innings.
Diamondbacks: Marte was shaken up after he fouled the first pitch of the game off his right leg. After he was checked on by a trainer and jogged in foul territory, Marte singled to left on Steele's next pitch. He departed in the seventh with right knee soreness.
Cubs: RHP Marcus Stroman (rib cartilage fracture) is expected to throw live BP on Monday. ... RHP Michael Fulmer (forearm strain) had a bullpen session on Friday that went well, according to the team.
Right-handers Brandon Pfaadt (1-8, 6.27 ERA) and Kyle Hendricks (5-7, 3.73 ERA) take the mound on Sunday for the series finale. Pfaadt was charged with three runs in 3 2/3 innings in Arizona's 3-2 loss to Colorado on Tuesday night. Hendricks is 1-1 with a 3.15 ERA in his last six starts for Chicago.