HOUSTON (AP) — Pinch hitter Jed Lowrie delivered a two-run double in the eighth inning and the Houston Astros stung Philadelphia, rallying for a 6-4 victory Thursday night that ended the Phillies’ seven-game winning streak.

The Phillies’ surge had pushed them within three games of St. Louis for the second NL wild-card spot.

Philadelphia couldn’t hold an early 4-0 lead, and Lowrie’s two-out put the Astros ahead 5-4.

Matt Dominguez hit a three-run homer for Houston, which has the worst record in the majors.

Philadelphia’s bullpen had pitched four scoreless innings after an early exit by starter Tyler Cloyd before running into trouble in the eighth.

Phillippe Aumont (0-1) took over in the eighth with a 4-3 lead and walked Jason Castro with one out. Pinch runner Jordan Schafer was caught stealing on a strong throw by catcher Erik Kratz from his knees.

But Aumont walked Dominguez and plunked pinch-hitter Scott Moore on the foot. Jake Diekman, the fifth Phillies reliever of the game, gave up Lowrie’s hit that stopped a string of 21 consecutive scoreless innings pitched by Philadelphia’s bullpen.

Brandon Barnes pushed the lead to 6-4 with an RBI single.

Wesley Wright (1-2) got the last two outs of the eighth for the win. Wilton Lopez allowed a hit in a scoreless ninth for his fifth save.

Kratz broke an 0-for-16 skid with an RBI double to give Philadelphia a 1-0 lead in the second.

The Phillies scored three times in the third. Juan Pierre and Chase Utley hit consecutive one-out singles and Ryan Howard had a sacrifice fly. John Mayberry Jr. and Kevin Frandsen added RBI singles.

Justin Maxwell and Castro hit consecutive singles in the fourth before Dominguez’s shot. The drive broke an 0-for-13 streak for Dominguez and was his third three-run homer in the last seven games.

Houston starter Lucas Harrell allowed seven hits and four runs in 5 2-3 innings to remain winless since Aug. 14.

Pinch hitter Pete Orr singled with two outs in the sixth and Harrell issued consecutive walks to load the bases. Harrell was lifted after the second walk, and jawed at plate umpire Bill Miller on his way to the dugout and was ejected.

He was replaced by Xavier Cedeno, who retired Utley to end the threat.

Cloyd yielded five hits and three runs in three-plus innings.

Cloyd retired his first six batters before Jimmy Paredes singled to start the third. Jose Altuve hit a two-out single and Cloyd hit Fernando Martinez to load the bases before getting Brett Wallace on a grounder.

It was the second tough start for Cloyd, who had his contract selected from Triple-A Lehigh Valley on Aug. 29. He allowed eight hits and four runs in four innings of his last start, but received a no-decision.