The Astros, who are 4-2 so far on the road trip against the Red Sox and Yankees, improved to 11-39 when not hitting a home run.
"That's a good ballgame there," manager Bo Porter said. "We have relied on the home run quite a bit, and today was a prime example of keeping the line moving, and I felt guys had great at-bats. [Hitting coach] John Mallee did a great job of preparing those guys for those at-bats, and they did a great job of executing."
Scott Feldman (7-9) won for the third time in four starts for the Astros by allowing eight hits and two runs in 6 2/3 innings and striking out a season-high seven. In beating the Yankees for the second time this year, Feldman has eight quality outings in his past 11 starts.
The Astros' bullpen came up with several big outs in picking up the final 2 1/3 innings, with Kevin Chapman retiring Jacob Ellsbury on a strikeout to end the seventh and strand runners at second and third.
"That's probably the biggest part of the game right there, pick me up, leaving a couple guys on base like that," Feldman said. "I owe him a dinner or something for that."
Josh Fields worked a scoreless eighth, and Jose Veras picked up his first save with the Astros since he had 19 for them last year by retiring Ellsbury on a fly ball to right field to end the game with runners at first and second. Veras handled the ninth because closer Chad Qualls was dealing with back stiffness.
"There wasn't a chance I could make a better pitch than that one [to Ellsbury], because if I don't make that pitch, then it's going to be 3-1 [count] and I'm going to be in the situation [where] they can tie the ballgame with one swing," Veras said. "So I just went right at home with my best pitch, my sinker."
The Astros were without a baserunner until Robbie Grossman singled to start the fourth and scored on a double by Dexter Fowler. A solo homer by Stephen Drew in the fourth and a safety-squeeze bunt by Ellsbury in the fifth put the Yankees ahead, 2-1.
"We've got to find a way to score more than two runs," Yankees manager Joe Girardi said. "It's hard to win when you only score two runs. Our pitching has been pretty good, but that's a tall task."
The seventh-inning outburst began when Jason Castro drew a leadoff walk from starter Michael Pineda. Lefty reliever David Huff struck out Jon Singleton before giving up a single to Marwin Gonzalez to put runners at first and second. Esmil Rogers came in from the bullpen and gave up four consecutive singles, including RBI hits by Jake Marisnick (2-for-4) and Jose Altuve around a go-ahead two-run single by Robbie Grossman (2-for-5).
The five consecutive singles by the Astros in the seventh came on a span of 10 pitches and resulted in the 5-2 lead.
"I thought the guys locked into their at-bats and had an idea of exactly what it is they were looking [for], what they wanted to do, and they did a good job of putting good swings on those pitches," Porter said.