The Giants won for the ninth time in 11 games earlier in the day, but the Dodgers' rally kept their National League West lead at two games. They are 14-4 against Arizona this year.
Before the three-run eighth inning, the Dodgers got a two-run homer from Adrian Gonzalez and a solid start from Hyun-Jin Ryu, who pitched six scoreless innings before tiring and allowing two runs in the seventh. He finished with nine strikeouts and 114 pitches, tying a career high.
After Gordon's two-out infield single in the third inning, 13 consecutive Dodgers were retired until Juan Uribe greeted reliever Daniel Hudson with a single off the glove of shortstop Cliff Pennington leading off the eighth.
Roger Bernadina, called up earlier in the day, pinch-ran for Uribe. After Joc Pederson sent left fielder Nolan Reimold against the fence to haul down his opposite-field drive, Justin Turner batted for A.J. Ellis and hit a broken-bat roller to third baseman Aaron Hill, whose throw to second base was beaten by a hustling Bernadina.
"That kind of changed the inning," said manager Don Mattingly, who didn't have Bernadina on Wednesday, when the Dodgers missed a chance to beat the Nationals by not running for Ellis because they were running low on players.
Andre Ethier, hitting for winning reliever Brian Wilson, flied out to right. Gordon fouled off three 3-2 pitches before sending a bouncer up the middle that scored Bernadina and didn't appear at all fatigued as he celebrated rounding first base.
"He was throwing hard, mixing pitches, and just left a pitch out over the plate," said Gordon.
Ramirez then pulled a ground-rule double that was touched by a fan reaching out of the left-field box seats, but umpires ruled that Gordon would have scored from first and Ramirez was placed at second base.
Kenley Jansen pitched the ninth for his 41st save, getting defensive gems from Gordon and first baseman Gonzalez to help strand a runner at third base.
"Dee's hit was big and Hanley's hit was big, because Kenley was running low on fuel and it was nice he had extra runs with a guy on third," said Mattingly.
Gordon scored the first Dodgers run after his first-inning double on Gonzalez's 20th home run. Gonzalez also has a team-leading 94 RBIs. It's his eighth season with at least 20 home runs and he's on pace for a seventh 100-RBI season. He's played in a team-high 138 of 141 games.
Arizona ran out of a chance in the top of the first inning, Ender Inciarte getting doubled off first when Chris Owings lined out to Matt Kemp on a hit-and-run.
Gordon led off the bottom of the first with a double just inside first base, and one out later Gonzalez launched his home run on the first pitch. Before the inning was over, however, the Dodgers also ran into a double play, with Kemp being doubled up running on a 3-2 pitch lineout by Carl Crawford.
In the second, the D-backs took a page from the Dodgers' offensive playbook, loading the bases with no outs and not scoring, as Ryu struck out Reimold and Chase Anderson sandwiched around a sliding catch by left fielder Crawford on Tuffy Gosewisch's sinking liner.
"Changed the momentum of the game," Mattingly said of Ryu's escape act.
"He's got the extra gear," Mark Trumbo said of Ryu. "He's got an extra two or three miles an hour in the tank when he needs it, and he really bears down in those situations."
In the seventh, Hill led off with a single and former Dodgers outfielder Cody Ross doubled him home high off the Dodgers' bullpen gate. Ryu caught Reimold looking for the first out. Mattingly paid a mound visit to Ryu, left him in to face Gosewisch again, and third baseman Uribe made a sliding stop of Gosewisch's grounder and threw him out for the second out.
"I wanted to see if he wanted that guy," Mattingly said of Ryu. "For Hyun-Jin, Zack [Greinke] and Kersh [Clayton Kershaw], it's their game. I saw in his face he was confident."
But pinch-hitter A.J. Pollock tied the game by bouncing an RBI single through the left side, ending Ryu's night.