HOUSTON – Analyzing the Yankees’ recent climb to the fringe of mediocrity, manager Joe Girardi said his starting pitchers had “gotten on a roll.” The exception was CC Sabathia, who had allowed 29 earned runs over his previous six starts while going 0-4.

But Sabathia joined the party Tuesday night at Minute Maid Park, allowing only two runs and four hits while pitching two outs into the seventh inning of a 6-3 victory over the Astros. Chase Headley and Aaron Hicks each drove in a pair of runs for a Yankees attack that had 13 hits, including nine off Astros starter Doug Fister. The Yankees (52-48) moved four games over .500 for the first time this season.

Andrew Miller got his ninth save after Dellin Betances produced a certain amount of drama. Entering with two outs in the eighth, Betances walked the first two batters he faced to load the bases before striking out Jason Castro looking.

In the first game of the series on Monday, the Astros scored their only run on a leadoff homer by George Springer off Michael Pineda. It took them one more out to get on the board against Sabathia (6-8), who threw an 89 mile per hour fastball that No. 2 hitter Marwin Gonzalez deposited in the leftfield seats for a quick 1-0 lead.

But just as Pineda did, Sabathia recovered well from that first-inning hiccup to start stringing together outs. After giving up a two-out walk in the first, Sabathia retired 11 of the next 12 hitters he faced, allowing only a one-out walk to Springer in the third before giving up his second hit of the game, a one-out single by Carlos Gomez in the fifth.

One night after they struggled to scratch out two runs against reigning Cy Young winner Dallas Keuchel, the Yankees came to life against Fister (10-7). Brian McCann led off the second with a single and advanced to third on a double by Mark Teixeira, whose bat is starting to grow warm.

McCann scored the tying run on a sacrifice fly by Didi Gregorius, Starlin Castro singled to move Teixeira to third and a single by Headley gave the Yankees a 2-1 lead. They loaded the bases on a walk to Brett Gardner, but the rally died when Jacoby Ellsbury popped out to shortstop.

The Yankees made it 3-1 in the third when Carlos Beltran singled, went to second on a wild pitch, moved to third on a fielder’s choice and scored on Castro’s infield single

The Yankees broke it open in the fifth with three more runs off Fister. McCann was hit by a pitch before Teixeira singled and Castro was given an intentional one-out walk to load the bases for Headley, whose sacrifice fly drove in McCann. No. 9 hitter Aron Hicks, who came into the game with a .191 average, tripled into the rightfield corner to score Teixeira and Castro for a 6-1 lead. That was the end for Fister.

After cruising through the sixth, Sabathia was tagged for a leadoff homer in the seventh by Evan Gattis. The Yankees starter got two more groundouts, but when Gomez singled, Sabathia was done after 103 pitches.

Reliever Anthony Swarzak struck out pinch hitter Preston Tucker to get out of the seventh with a 6-2 lead. Swarzak gave up Gonzalez’s second homer of the game with one out in the eighth but struck out two and walked one before giving way to Betances.