McCarthy, who was beaten by Keuchel and the Astros on June 11 while he was with the D-backs, threw his ninth career complete game by spinning a four-hit shutout as the Yankees avoided the sweep with a 3-0 win at Yankee Stadium.
"I feel like I pitched just as good as McCarthy, but he was better today," Keuchel said.
Keuchel's five complete games, two of which have come in losing efforts, are the most in a season by an Astros lefty since Mike Hampton had seven in 1997.
"Keuchel was outstanding," manager Bo Porter said. "Just the one inning there, and they were able to put some balls in places where we couldn't defend them. To their credit, they were able to put up a three-spot. Dallas Keuchel, don't take anything away from him."
Neither Keuchel nor McCarthy walked a batter, which helped lead to a fast game time of 2 hours, 7 minutes -- the shortest of the season for the Astros and the shortest nine-inning Yankees home game since 1996.
McCarthy (5-2 with New York, 8-12 overall), making his eighth start since being traded to the Yankees, used 107 pitches to throw his fourth career shutout.
"He was exactly what we needed," Yankees third baseman Chase Headley said. "That team played us tough this year, and after we put up some runs, it was great for him to come out and really dominate the game."
The Yankees' rally in the second began when Mark Teixeira rolled a single through a huge hole on the right side of the infield that was left vacated by second baseman Jose Altuve, who shifted to the other side of the base. Martin Prado then reached out to hit a pitch that was nearly in the dirt and poked it into left-center, hustling into second base to put runners at second and third.
If those hits weren't frustrating enough for Keuchel, Headley followed by hitting a pop fly down the right-field line that bounced into the corner for a two-run double. Headley's heady play of taking third on a grounder to third base allowed him to score on an Ichiro Suzuki sac fly to make it 3-0.
"It was just a bad sequence," Keuchel said. "Teixeira hit a ball through the shift, and I thought Prado hit a pretty good pitch of mine, and Headley got his first hit on an outer-half fastball since he's been a Yankee. I couldn't ask for any better pitches, so that's just the quality of those guys, and they beat me the second inning."
Keuchel sent down 20 of the final 23 batters he faced.
"He looked like he was in complete command the whole time," Porter said. "Even the inning where he gave up the three runs, it's not like those were bad pitches. So he did a tremendous job."
The Astros' best chance to get to McCarthy came in the seventh, when Chris Carter -- whose game-winning homer in the ninth inning Tuesday was his only hit in his previous 16 at-bats -- led off with a single. He was erased on a fielder's choice by Dexter Fowler, who would have scored on a Marc Krauss hit to right had it not bounced over the wall for a ground-rule double.
"With Dexter running, and when he gets those long legs going, he's going to score from first a lot of the times," Krauss said. "It's just one of those plays where the short porch cost you there, possibly. It's something you can't really worry about. I was able to keep it fair and try to get something going, but McCarthy made some good pitches to get out of it a couple of times today when we did have something going."
McCarthy struck out Jon Singleton and got Carlos Corporan to fly out and went on to retire the final eight batters he faced.
"He was on his game, to say the least," Krauss said. "Talking with other guys, he just didn't throw the ball over the middle of the plate. All the pitches I saw were either on the outside corner or inside corner or just off. He did a good job of locating, and when pitchers can locate -- and he has two good pitches, his sinker and cutter -- it's going to make it tough on the hitters, which it was for me today."