Phoenix: Two of the most famous clubs in Major League Baseball came from a long way back to earn spots in the post-season on Thursday.

The Los Angeles Dodgers with their new owners turned around a disastrous first half of the season to win the National League West pennant, three months after sitting in last place. The Boston Red Sox and their new manager wiped away memories of a last-place finish last season in the American League East to ensure at least a playoff berth.

Burdened by high expectations and a horrible start, the Dodgers relieved their pent-up pressure with a joyful celebration after becoming the first team this year to clinch a playoff spot. Hanley Ramirez homered twice as they rallied to beat the Arizona Diamondbacks 7-6.

“I want to keep going,” Ramirez said. “I think that we’ve got a couple of more steps to do. We’ve got to keep working and stay together all the way through to the end.”

Ramirez was back in the lineup after being sidelined five of six games with an irritated nerve in his lower back. He’s played 1,090 regular-season games but will be making his first trip to the postseason. Only three active players have played more games without making the playoffs.

Despite an NL-high payroll of $214 million-plus on opening day, the Dodgers got off to a 30-42 start and were last in the division, 9 games behind the first-place Diamondbacks, before play on June 22. Los Angeles has gone 58-23 since, including a 42-8 run that coincided mostly with dynamic Cuban defector Yasiel Puig’s call-up to the majors.

“This is a great accomplishment for these guys,” manager Don Mattingly said. “We put a great team together and a big payroll with huge expectations. A lot of time that falls apart and it had a chance to fall apart during the season, I thought. The players came together, we got healthy, and then we just rolled.”

The Dodgers trailed 6-3 in the sixth and A.J. Ellis hit a tie-breaking homer off Josh Collmenter (4-4) leading off the eighth. J.P. Howell (2-1) got two outs for the victory.

The Pirates had a 1-0 win over the Padres, with Pedro Alvarez hitting his NL-leading 34th homer as they moved a game in front of Cincinnati for the top wild-card spot in the NL. Pittsburgh moved within one game of first-place St. Louis in the NL Central.

Washington kept alive its slim hopes of reaching the playoffs with a 3-2 win over the Florida Marlins. Despite winning 11 of 13 in a belated run, the Nationals trail Cincinnati by five games for the final NL wild-card spot with nine games remaining.

At Denver, Corey Dickerson’s RBI triple with one out in the bottom of the 15th inning gave Colorado at 7-6 win over the Cardinals. Charlie Blackmon finished with four hits and Troy Tulowitzki and Todd Helton homered for the Rockies in equaling the second-longest game in Coors Field history.

In other games, San Francisco’s Madison Bumgarner struck out 10 in seven innings of four-hit ball as the Giants edged the Mets 2-1, and the Cubs beat the Brewers 5-1 at Milwaukee to end a five-game losing streak.

There were celebrations at Boston after a 3-1 win over of Baltimore got the Red Sox into the playoffs for the first time since 2009.

Coming off a last-place finish and a 69-93 win-loss record last season - their most losses since 1965, the Red Sox have rebounded under first-year manager John Farrell and ensured at least a wild-card berth in the postseason. They lowered their magic number to two for clinching the AL East.

Boston scored all its runs in the second on Stephen Drew’s two-run homer and Dustin Pedroia’s RBI single.

At Toronto, the New York Yankees lost for the fifth time in six games, losing 6-2 to the Blue Jays.

Hiroki Kuroda lost his fifth straight decision, allowing two runs in the third inning and a solo home run to Anthony Gose in the sixth. Adam Lind added a three-run homer in the seventh off Joba Chamberlain.

New York, which began the night 2= games behind for the second AL wild-card berth, is in danger of missing the playoffs for only the second time in 19 seasons.

Detroit, meanwhile, pushed its AL Central lead to 6 1/2 games with a 5-4 win over the Mariners. Prince Fielder had three hits and scored the tiebreaking run in the seventh inning on a close play at the plate for the Tigers, who trailed 4-3 after Seattle’s Dustin Ackley hit a three-run homer in the fifth.

The Indians edged the Houston Astros 2-1 with Matt Carson’s single with two outs in the 11th inning giving Cleveland the win as it closed within a half-game in the AL wild-card race.

Texas and Tampa are tied atop the AL wild-card race after the Rangers beat the Rays 8-2 in Florida to split their four-game series.

The Rangers won the season series with the Rays 4-3, earning home-field advantage should the teams finish in tie for the two wild-card spots. They each have 10 games left.

Yu Darvish won for the first time in seven starts since Aug. 12. Darvish (13-9) made it through five innings despite walking six.