After Joe Girardi watched his club go 0-2 against the Red Sox to start this 10-game homestand, he declared Sunday night’s series finale essentially a must-win.

“This is probably as important a game that we’ve had in July in a long time,” Girardi said Saturday night.

His club responded 24 hours later and hasn’t stopped responding.

Behind six shutout innings from Michael Pineda and a late surge from their offense, the Yankees won their fourth straight game Wednesday night, 5-0, over the Orioles in front of 35,681 at the Stadium.

The Yankees (48-46) climbed within 5 ½ games of the AL East-leading Orioles (53-40) with a chance at a four-game series sweep Thursday when CC Sabathia takes on righthander Chris Tillman.

The Yankees, who have allowed a total of three runs in their last four games, also managed to inch two games above .500 for the first time since April 12, when they were 4-2.

Pineda entered the game 3-9 with a 5.56 ERA and having allowed 18 homers in 18 starts this season. Against a depleted Orioles lineup he only allowed five hits.

A stomach bug has hit the Orioles hard with third baseman Manny Machado and manager Buck Showalter the latest to miss a game. First baseman Chris Davis missed his third straight game with the flu-like symptoms that put him in the hospital Sunday night. Catcher Matt Wieters also didn’t play after being hit by a pitch on his right foot on Monday. Bench coach John Russell filled in for Showalter.

With as good a slider as he’s had this season, the 27-year-old limited the Orioles to 1-for-9 with runners in scoring position, struck out eight and walked two.

Dellin Betances pitched a scoreless seventh and, after Ronald Torreyes tripled and scored in the bottom half to make it 4-0, Nick Goody came on for a scoreless eighth. Chasen Shreve pitched a 1-2-3 ninth as the Yankees’ bullpen ran its scoreless innings streak to 28 2/3 innings.

Four of the Yankees’ runs came against Yovani Gallardo, who allowed four runs and five hits in seven innings.

Brett Gardner tripled and scored in the first and Mark Teixeira, returning to the lineup after missing three straight games with a sore left foot, homered in the fourth, then brought a run home in the sixth by drawing a bases-loaded walk that made it 3-0.

Carlos Beltran hit his team-leading 20th homer in the eighth inning against righthander Chaz Roe, to make it 5-0. Beltran had two hits and two RBIs, giving him a team-leading 60.

Gardner, swinging at the first pitch with one out in the first, drove one to the track in right-center, where the ball glanced off the glove of rightfielder Joey Rickard for a triple. Jacoby Ellsbury popped to short but Beltran’s sacrifice fly to center made it 1-0.

Pineda stranded two in the second — both runners reached with two outs, one via error — and three in the fourth, the latter a far more complicated jam.

Adam Jones led off the inning with a single to right and Mark Trumbo walked. Pineda struck out Pedro Alvarez on a 2-and-2 slider and allowed J.J. Hardy’s single that loaded the bases. Pineda, however, struck out Nolan Reimold and Ryan Flaherty on sliders to end the inning.

The Yankees tacked on a run in the bottom half with one out when Teixeira lined a first-pitch slider into the seats in right for his eighth homer to make it 2-0.

Notes & quotes: While there had been speculation the Yankees would call up RHP Chad Green to start in place of RHP Masahiro Tanaka Friday, which would give the latter an extra days’ rest, Girardi said that was not currently the plan. “As of right now we’re not doing anything,” Girardi said. “I don’t have anything concerning him [Green] right now, no.” . . . 3B Chase Headley was scratched from Wednesday’s lineup, and replaced by Torreyes, for what the club characterized as “personal reasons.”