The Dodgers took two of three in an important series for Arizona, which trails the NL West-leading Dodgers by seven games.
Kike Hernandez had three hits, including a triple and a double, and Brett Anderson pitched seven strong innings for his third straight victory as the Dodgers beat the Diamondbacks for the ninth time in the past 10 meetings.
Anderson (5-4) stranded six runners and allowed one run and seven hits, striking out seven and walking two. The run came on Aaron Hill's home run in the sixth.
"He's healthy again," Diamondbacks manager Chip Hale said of Anderson. "He has always been a pretty highly sought-after guy. Even when we drafted him here. He got it going on right now."
Anderson accomplished something important to him.
"It wasn't the best, but I'll take it," he said. "I can go to my grave knowing I got Paul Goldschmidt out twice, which has been an issue for me this year."
Hernandez ripped a leadoff triple to start the game and scored on Howie Kendrick's sacrifice fly.
The Dodgers' defense, and some Diamondbacks' blunders, got L.A. out of a jam in the bottom of the inning. Anderson picked off Nick Ahmed trying to steal and catcher A.J. Ellis raced up the first base line to catch a throw from first baseman Scott Van Slyke and tag out A.J. Pollock, who had stopped briefly after rounding first base on a single.
"That wasn't very good," Hale said. "You give away two outs right away, against a good team, it's not easy to overcome."
The Dodgers scored three runs in the third to take a 4-0 lead on doubles by Ellis and Hernandez, followed by Kendrick's run-scoring single and an RBI double from Justin Turner.
Pollock had three hits and scored on Hill's sacrifice fly in the eighth off reliever Yimi Garcia. Arizona brought the tying run to the plate in pinch-hitter Welington Castillo, but he flied out to end the inning.
The Diamondbacks got closer on David Peralta's solo home run off Dodgers closer Kenley Jansen in the ninth, but Jansen recovered and earned his 13th save.
"It's tough against a closer like Jansen," Hale said. "He doesn't lose his cool after the big home run by Peralta and he shut us down."
Robbie Ray (2-4) took the loss after allowing four runs and seven hits with six strikeouts and two walks in six innings.
"I was able to throw my fastball to both sides of the plate," Ray said. "I just hung a few pitches, offspeed pitches, and they took advantage of it."
A WALK TO REMEMBER
Goldschmidt's hitting streak ended at 11 games after he went 0 for 3 with a walk. But the walk was his 62nd of the season, which gave the Diamondbacks star the most in club history before the All-Star break.
EPIC STOLEN BASE DROUGHT
The Dodgers haven't stolen a base since June 7, and their 23-game streak without a steal is the longest in modern franchise history (since 1900), according to Elias Sports Bureau. When Jimmy Rollins was thrown out trying to steal second in the eighth inning, it marked the sixth time the Dodgers have been caught stealing during the 23-game run.
Dodgers: RHP Brandon Beachy was to make his fourth rehab start with Triple-A Oklahoma City on Wednesday. He is coming back from right elbow surgery. ... RHP Brandon League pitched a scoreless inning in relief Tuesday night for OKC in a rehab outing as he returns from a right shoulder injury. ... OF Carl Crawford was the DH for Class A Rancho Cucamonga on Tuesday and was expected to play in the field this week. He's on the mend from a right oblique strain.
Diamondbacks: LHP Patrick Corbin had been slated to work in the minors this week as his long comeback from major elbow surgery nears its end, but Hale said Corbin could start for Arizona on Saturday against Colorado.
Dodgers: Los Angeles gets Thursday off, then returns home for a three-game series against the New York Mets with Clayton Kershaw (5-6, 3.20) on the mound. Kershaw has lost three consecutive starts for the first time in his career.
Diamondbacks: RHP Jeremy Hellickson (5-5, 5.38) faces the Colorado Rockies in the opener of a four-game series Thursday. Hellickson has won four of his last six decisions and has won all three of his most recent home starts.