PHOENIX -- Hanley Ramirez had four hits and two home runs and A.J. Ellis hit a tiebreaking home in the eighth inning to lift the Los Angeles Dodgers to the National League West title with a 7-6 victory over the Arizona Diamondbacks on Wednesday afternoon.
Ramirez hit a three-run homer for a 3-0 lead in the third inning and his bases-empty home run leading off the seventh tied the score at 6.
Ellis hit the first pitch he saw from Josh Collmenter (4-4) leading off the eighth as the Dodgers (88-65) became only the fourth team in major league history to finish a season in first place after being in last place on July 1 or later.
The Dodgers were 38-43 and in fifth place, 3 1/2 games behind the Diamondbacks on July 1, but took command of the division with a 53-13 run that began the final week of June. The only other teams to pull off a midseason worst to first are Seattle (1995), the New York Mets (1973) and the Boston Braves (1914, according to Elias).
The Dodgers also are the second team in as many seasons to win a division after trailing by as many as 9 1/2 games. Oakland trailed Texas by 9 1/2 before winning the American League West last year.
Kenley Jansen pitched the ninth for his 26th save.
Ellis had three hits, and the homer was his eighth of the year.
Ramirez, who also in the singled in the first and fifth innings, raised his batting average to .351. He has 20 homers and 57 RBIs in 81 games, and the Dodgers are 48-23 in games he has started.
Martin Prado had two hits and two RBIs for the Diamondbacks (77-75), who had won four of their last five.
Paul Goldschmidt had a run-scoring double for his NL-leading 119th RBI and starting pitcher Wade Miley contributed a two-run double.
Ramirez hit his three-run homer after Miley walked Rick Nolasco and Yasiel Puig to open the third inning. Puig was forced at second base when he did not get a good jump on Jerry Hairston Jr.'s looping hit down the first field line.
The Diamondbacks scored six runs and had seven hits against Nolasco for a 6-3 lead in the bottom of the third.
After leadoff singles by Adam Eaton and A.J. Pollock, Goldschmidt hit a ground-rule double down the right field line before Prado tripled down the right-field line to tie it at 3.
Miguel Montero singled in Prado with one out and Miley doubled in the final two runs of the inning after a Didi Gregorius double.
Nolasco, who had been 3-0 with an 0.83 ERA against Arizona entering the game, gave up nine hits and struck out five in five innings.
Miley gave up three runs, five hits and four walks in five innings.
NOTES: Dodgers 1B Adrian Gonzalez (quadriceps) was held out of the starting lineup on Thursday, although manager Don Mattingly did not go so far as to call Gonzalez's condition an injury. "For me, it's more than a cramp, but it's less than a full-blown injury. But it is enough to sit him," Mattingly said. Gonzalez entered the game as a defensive replacement in the ninth inning. ... Dodgers OF Andre Ethier (ankle) expects to take batting practice in San Diego on Friday. He has not played since tweaking the ankle while running the bases last Friday. ... Dodgers RHP Edinson Volquez will start at San Diego on Friday, his first start against the Padres since being released by them on Aug. 27.