NEW YORK — Didi Gregorius and Matt Holliday each hit a go-ahead homer and New York piled on from there, lifting the Yankees over the Los Angeles Angels 8-4 on Wednesday night to snap a season-high seven-game losing streak.

New York’s skid was its longest since 2007. The Yankees haven’t lost eight straight since August 1995. They moved back ahead of Boston for first place in the AL East a night after losing the division lead for the first time since mid-May.

Jordan Montgomery (5-4) pitched two-run ball over 52/3 innings. Relievers Chad Green and Dellin Betances got the ball to Tyler Clippard in the ninth, but Clippard allowed a two-run homer to Martin Maldonado, his second of the game. Aroldis Chapman came on to close out.

Ricky Nolasco (2-9) lost his seventh consecutive start to match George Brunet’s franchise record from 1967. The right-hander allowed the homers to Holliday and Gregorius, and has given up 23 long balls this season, tied for the major league lead with Cincinnati’s Bronson Arroyo.

Montgomery, pitching with an extra day of rest, gave up five hits, including a two-run homer by Maldonado, while striking out five. The left-hander is 3-1 with a 2.55 ERA over his past six starts.

Maldonado had the first multihomer game of his career. He and Andrelton Simmons each had three hits for the Angels.

Austin Romine added a two-run single for New York in the sixth.

NATIONAL LEAGUE

MARLINS 2, NATIONALS 1: Max Scherzer’s bid for the third no-hitter of his big league career ended with one out in the eighth inning, and he then gave up two unearned runs and host Miami rallied to beat Washington.

After backup catcher A.J. Ellis reached on an infield single for Miami’s first hit, an error by first baseman Adam Lind and a hit batter loaded the bases with two outs. Scherzer threw a wild pitch that scored the tying run, and Giancarlo Stanton lined an RBI single – the Marlins’ only other hit – to put them ahead.

PADRES 3, CUBS 2: Erick Aybar hit a tying homer in the sixth inning, Luis Torrens walked with the bases loaded against Koji Uehara in the eighth and San Diego stopped a three-game losing streak by winning in Chicago.

Chicago rookie Ian Happ hit a two-run homer in the fourth against reliever Craig Stammen, going deep for the second straight game and third time in four.

CARDINALS 7, PHILLIES 6: Tommy Pham’s second solo homer off Hector Neris in the ninth tied it and St. Louis rallied from a 5-0 deficit to win in 10 innings.

Jedd Gyorko hit a two-run homer and pinch-hitter Jose Martinez also connected for St. Louis.

INTERLEAGUE

RAYS 8, REDS 3: Tampa Bay left fielder Mallex Smith rushed in to tag out speedy Billy Hamilton after a lengthy rundown, highlighting the Rays’ win at home.

Hamilton stole his 31st base in the fourth inning. But he later got trapped when he tried to score from second on a two-out grounder by Eugenio Suarez that shortstop Daniel Robertson bobbled.