LOS ANGELES (AP) -- Scott Van Slyke and Juan Uribe each tied the score with a clutch home run for the Dodgers. Then it was Aaron Hill's turn to get an even bigger hit against Chris Perez.
Hill lined a two-run single in the 12th inning and Miguel Montero homered, leading the Arizona Diamondbacks to a 4-2 victory Friday night over Los Angeles.
Arizona took a 2-1 lead in the ninth when pinch-runner Tony Campana scored on a wild pitch by reliever Chris Withrow, who was attempting to walk Martin Prado intentionally after falling behind him 2-0.
"I've seen that before, but never been a part of it," Dodgers catcher Tim Federowicz said. "I think if I would've jumped a little higher I might've got it."
Uribe responded in the bottom half with a one-out homer off closer Addison Reed. Six of Uribe's last eight regular-season home runs have come against the Diamondbacks -- three in an 8-1 victory last Sept. 9 at Dodger Stadium.
But in the 12th, Perez (0-1) gave up a leadoff double to A.J. Pollock and plunked pinch-hitter Cliff Pennington on the left foot as he squared to bunt. Gerardo Parra advanced the runners with a sacrifice before Hill broke the tie.
The second baseman was hitless in five previous at-bats and didn't hit the ball out of the infield. A few well-chosen words of encouragement from manager Kirk Gibson helped change his night dramatically.
"Gibby told me in the seventh or eighth inning, 'You're going to get the game-winning hit tonight," Hill said. "He knew I was frustrated a little bit, so it just picked me up a little bit and I appreciated it. I don't know if I believed him at the time, but it worked out."
Arizona snapped a six-game losing streak and improved to 5-14, the worst record in the majors.
Joe Thatcher (0-1) pitched 1 1-3 scoreless innings and six-year veteran Trevor Cahill got three outs for his first major league save. Cahill was 0-4 with a 9.17 ERA in four starts before he was demoted to the bullpen.
"I don't think I was spending all day today thinking I was going to get a save tonight," Cahill said. "I guess I got lonelier down there with everybody leaving. But it was fun. It's a lot different than starting, because your adrenaline goes so quick. Then it's over, and you don't know what happened."
The Dodgers had won the first five meetings with the Diamondbacks this year, including both ends of their season-opening series in Sydney and last weekend's three-game set at Phoenix.
Arizona starter Wade Miley took a two-hitter and a 1-0 lead into the seventh in his rematch with Zack Greinke, but Van Slyke drove Miley's 108th and final pitch the other way into the right-field pavilion leading off the inning.
Miley struck out eight and walked five in his third start of the season against Los Angeles. Both of the left-hander's losses have come against the defending NL West champions, including an 8-5 victory by Greinke last Saturday.
"Miley had better command tonight. He attacked more and threw a lot more strikes early," Dodgers manager Don Mattingly said. "The two games before, we were getting into favorable counts."
Montero homered in the sixth off Greinke, who struck out eight over six innings as Los Angeles opened a 10-game homestand.
Hanley Ramirez returned to the Dodgers' lineup and grounded into a double play on the first pitch he saw after Miley walked his first two batters. Ramirez was hit on the left hand by a pitch from San Francisco's Ryan Vogelsong on Wednesday night and sat out Thursday's game.
Miley fanned Adrian Gonzalez his first three times up, but the Dodgers' cleanup hitter singled in the 10th to extend his hitting streak to 13 games.
Yasiel Puig batted leadoff for the fourth time and was 0 for 3 with three walks and three strikeouts.
NOTES: The Dodgers haven't won their first six meetings against a team in their own division since 1988, when they started 6-0 against Atlanta. The Braves were in the NL West at that time. ... Thatcher has not allowed an earned run in his last 32 appearances against the Dodgers spanning 19 innings. ... Thirteen of the last 14 home runs Greinke has allowed have been solo shots, including the last nine. ... Tommy Lasorda and his wife, Jo, celebrated their 64th wedding anniversary at Dodger Stadium. They were a big hit on the "Kiss-Cam" after the fourth inning.