New York won for just the third time in 10 games. Chase Headley hit an early two-run double and the Yankees backed McCarthy with flawless fielding.
The Yankees' fans also made fine plays - sitting in the first row behind the Houston dugout, comedian Chris Rock wound up with a foul ball off the bat of Astros rookie Jon Singleton, and he gave the souvenir to a young girl as the crowd cheered.
McCarthy (5-2) outpitched Dallas Keuchel (10-9) as they both threw complete games without a walk. The Yankees had been shut out in McCarthy's previous two starts.
McCarthy struck out eight in his fourth career shutout and first this season. He was 3-10 with Arizona before being traded to the Yankees in July.
Keuchel gave up seven hits and struck out five.
The Astros had won three in a row overall. They were trying to become the first team to come into Yankee Stadium at least 20 games under .500 and sweep a series of three games or more since Milwaukee did it to close the 1972 season, STATS said.
The Yankees took a 3-0 lead in the second when a double by Martin Prado set up Headley's two-run double. Prado and Headley were the only two Yankees starters to previously hit against Keuchel.
Ichiro Suzuki added a sacrifice fly later in the inning.
Dexter Fowler hit a broken-bat double in the Houston fourth - the barrel reached the infield dirt, the ball two-hopped off the right-field wall - that put runners at second and third. Marc Krauss followed with a hard grounder off McCarthy's leg and, after taking a moment to locate the ball on the grass, the lanky pitcher zipped a throw to first that ended the threat.
McCarthy escaped another second-and-third jam in the seventh when Singleton struck out - right after hitting a foul pop to the third-base side that Rock recovered - and retiring Carlos Corporan on a flyball.
Astros: Closer Chad Qualls didn't pitch in a save situation Wednesday night because of a back problem. Manager Bo Porter said the right-hander got treatment, but didn't want to comment on Qualls' availability.
Yankees: RHP Masahiro Tanaka is ready to throw to hitters on the side Saturday in his latest comeback effort from an elbow tear. The session will most likely be at Yankee Stadium. ... Slumping Carlos Beltran again didn't play because of his balky right elbow. He recently had his third cortisone shot. Manager Joe Girardi said the team should have a ''good idea by Saturday where we're headed with this.''
Astros: RHP Brad Peacock (3-8, 5.47 ERA) starts Friday night at Cleveland vs. RHP Carlos Carrasco (5-4, 3.27). Peacock will be making his third start since returning from the minors.
Yankees: RHP Shane Greene (3-1, 2.91) starts at Yankee Stadium against White Sox LHP John Danks (9-8, 4.94) on Friday night. None of the Chicago hitters have ever faced Greene.