PHOENIX -- Hyun-Jin Ryu made one mistake, and it cost him and the Dodgers.
"We were fortunate, but sometimes you have to win 2-1 with two hits," Arizona manager Kirk Gibson said. "We got two hits but we made the most of them."
It marked the third time in Diamondbacks history that they won with two or fewer hits.
With Los Angeles' fourth loss in a row and the Diamondbacks' third straight win, the Dodgers' magic number to clinch the NL West remains four.
Los Angeles has lost 11 of 12, and the Dodgers' once 13½-game lead over Arizona only had shrunk to 9½ with 12 games to play.
"The last 11 are basically gone so they don't concern me at all," said Los Angeles manager Don Mattingly. "I can't get those back even if I wanted to waste energy on trying to figure out what happened to those 11. It really goes into what I always think about September. It's hard to win games and I don't care who you are."
Goldschmidt raised his NL-leading RBI total to 116 with his 33rd home run off Ryu (13-7). Goldschmidt has homered in each of his last two games after an 83-at-bat drought.
"He threw a fastball first pitch and I was looking for something over the plate," Goldschmidt said. "(Ryu) pitched great."
Ryu went the distance for his second complete game, allowing only the two runs on two hits in eight innings. He walked one, struck out four and retired 23 of the final 24 batters he faced.
"I threw 100 pitches but that one pitch was the decision-maker of the game," Ryu said. "It was an error on my part. I believe no matter how good a pitch it was, if it is a home run, it's a mistake."
Cahill (7-10) won for the fourth straight decision, holding Los Angeles to one run on two hits over 5 2/3 innings.
Brad Ziegler pitched the ninth for his 11th save but not without some drama.
Michael Young hit a pinch-hit single to center and Skip Schumaker singled to left. Juan Uribe tried to bunt the runners over, but Ziegler fielded the ball and threw to third to force Young for the first out. Nick Buss hit a soft bouncer to first for the second out as the runners advanced.
Mattingly then sent up Matt Kemp, who was activated off the 15-day disabled list earlier Monday. Ziegler got ahead 0-2 on two swinging strikes, wasted a pitch and then struck out Kemp on a lunging swing at on a curveball well low and outside.
"I've faced him a lot even before I got to Arizona, facing him in batting practice," Ziegler said. "I know what he'd trying to do and he knows what he wants to do against me. Luckily, I came out on top tonight."
Cahill was nearly untouchable over the first five innings, allowing only a single by Punto to start the game and a two-out walk to Puig in the first before retiring the next 13 in a row. But the right-hander quickly ran into trouble in the sixth with the Diamondbacks still holding a 2-0 lead.
Cahill walked Ryu, Punto doubled to the wall in left-center and Mark Ellis walked to load the bases. Cahill retired Adrian Gonzalez on a line drive to left and the runners held, but he then walked Puig to force home Ryu and cut Arizona's lead to 2-1.
"He's done that in the past," Gibson said of Cahill. "He just starts to lose it. You could just see he was aiming the ball."
"Our pitchers have been doing unbelievable lately," Goldschmidt said. "Our offense hasn't always been there but they've been tough."
Goldschmidt is tied with Reggie Sanders for eighth place on Arizona's single-season home run list and moved into sole possession of third place in RBIs behind Matt Williams' 142 in 1999 and Luis Gonzalez's 142 in 2000. ... Cahill has not pitched past the sixth since August 22, a span of four starts. ... Ryu's other complete game came on May 28 when he threw a two-hit shutout against the Los Angeles Angels. ... Kemp had played only once since July 5, going 3 for 4 with a double and homer before spraining his left ankle on a play at the plate in the ninth inning against Washington. ... Diamondbacks RHP Matt Reynolds, on the DL since June 10 with a strained left elbow, will undergo Tommy John surgery a week from Tuesday. Reynolds felt pain in the elbow during a throwing session on September 13. . RHP Zack Greinke (14-3) will take the mound for the Dodgers against LHP Patrick Corbin (14-6) and the Diamondbacks in the second game of the three-game set.