SAN FRANCISCO — Andrew McCutchen had two hits, including a two-run homer, pinch-hitter Matt Joyce had a key two-run single and the Pittsburgh Pirates rallied from a four-run deficit to complete a three-game sweep of the freefalling San Francisco Giants with a 6-5 victory Wednesday.

The Pirates won their fourth straight game and sixth in seven to remain a game behind St. Louis in the race for the NL wild card.

The Giants, who on Tuesday fell out of first place in the NL West for the first time in 97 days, lost their fourth straight. They fell to 9-21, the worst record in the majors since the All-Star break.

DODGERS 7, PHILLIES 2: Adrian Gonzalez hit two home runs and had five RBI to help Los Angeles extend its NL West lead with a victory at Philadelphia.

CUBS 6, BREWERS 1: Jorge Soler hit a three-run homer during a five-run first inning, Jon Lester pitched into the seventh for his fourth straight win, and host Chicago earned its 17th victory in 20 games.

ROCKIES 12, NATIONALS 10: D.J. LeMahieu had two more hits, Gerardo Parra drove in four runs, and Colorado beat Stephen Strasburg and the Nationals at Denver.

LeMahieu singled in his first at-bat to stretch his on-base streak to 10 plate appearances. He then struck out to end Colorado’s seven-run first inning.

REDS 3, MARLINS 2: Brandon Phillips drove in two runs in the seventh with his second double of the game and Cincinnati rallied to a win at home.

AMERICAN LEAGUE

BLUE JAYS 7, YANKEES 4: J.A. Happ won his 11th consecutive decision to become the first 17-game winner in the majors, and Melvin Upton Jr. hit a three-run homer that propelled Toronto at New York.

Darwin Barney had an early two-run double and Russell Martin added three hits to help Toronto take 2 of 3 in the series.

Happ (17-3) pitched into the eighth and extended the major’s longest active winning streak. He struck out nine and walked one.

WHITE SOX 10, INDIANS 7: Adam Eaton’s ninth-inning grand slam off closer Cody Allen capped a five-run rally and lifted Chicago to a win at Cleveland.

Cleveland was two outs from increasing its lead over Detroit to seven games, but the White Sox rallied to end a seven-game losing streak against the Indians.

ROYALS 4, TIGERS 1: Eric Hosmer hit a two-run homer in the ninth to give Kansas City a win at Detroit to complete a three-game sweep.

Hosmer broke up Anibal Sanchez’s no-hit bid with a double in the seventh after spoiling his perfect game with a walk in the fifth.

RANGERS 6, ATHLETICS 2: Yu Darvish struck out nine and Texas beat Oakland at home, giving the right-hander his first victory in his last 11 starts against the Athletics.

INTERLEAGUE

CARDINALS 8, ASTROS 2: Carlos Martinez took a no-hitter into the sixth, Jeremy Hazelbaker and Brandon Moss hit home runs, and visiting St. Louis won its fourth straight.

Martinez (11-7) pitched seven innings of three-hit ball, allowing a run while striking out seven .

RAYS 2, PADRES 0: Chris Archer struck out nine in 71/3 innings, Brad Miller homered again and Tampa Bay completed a three-game home sweep.

Archer (7-16) allowed four hits and a walk. He’s at risk of becoming the majors’ first 20-game loser since Detroit’s Mike Maroth (21) in 2003.