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. And it set up yet another important July game Thursday afternoon.

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

The Yankees (48-46) climbed within six games of the AL East-leading Red Sox and knocked the Orioles (53-40) out of first place. They can complete a four-game sweep when CC Sabathia faces 13-game winner Chris Tillman.

The Yankees have allowed a total of three runs the last four contests, and are two games above .500 for the first time since April 12, when they were 4-2.

advertisement | advertise on newsday

“You have to keep pushing,” Girardi said afterward.

“We know we can play with the best, these guys have been at the top of the division most of the year and we know if we play our ‘A’ game that we can beat good teams,” said Mark Teixeira, who went 1-for-2 with a homer, two RBIs and two walks. “And we’re going to have to if we’re going to stay in this thing.”

Though Teixeira produced at the plate, as did Carlos Beltran, who hit his team-best 20th homer of the season and drove in two runs to give him a team-high 60 RBIs, Wednesday night’s star was Pineda. The righthander came in 3-9 with a 5.56 ERA, having allowed 18 homers in 18 starts.

Against a depleted Orioles lineup, Pineda allowed five hits over six innings.

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.

Yankees videos

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

“It was pretty good tonight,” Pineda said of his slider. “Especially in those situations [with RISP], I didn’t want to make a mistake, I didn’t want to hang any sliders.”

Pineda, holding the 1-0 lead given to him in the first when Brett Gardner tripled and scored, loaded the bases with one out in the fourth, but struck out Nolan Reimold and Ryan Flaherty on sliders.

In the sixth, the lead now 2-0 because of Teixeira’s eighth homer in the fourth, Mark Trumbo reached third with one out. But Pineda struck out J.J. Hardy with a fastball and Reimold with another slider.

“When you can get outs with runners in scoring position, those are the most crucial outs of a game,” Girardi said. “That’s usually the difference in a game.”

advertisement | advertise on newsday

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 streak to 28 2⁄3 innings.

“It’s a contribution from every aspect,” Beltran said of the winning streak. “Pitching, offense and defense. In order for us to make a run, we have to be consistent and we’re being pretty consistent.”

Notes & quotes: There had been speculation the Yankees would call up Chad Green to start in place of Masahiro Tanaka Friday night, which would give the latter an extra day’s rest, but Girardi said that was not the plan, though he left some wiggle room. “As of right now,” he said, “we’re not doing anything.” . . . Chase Headley was scratched about 5 p.m. from the lineup, replaced by Torreyes, for what the club called “personal reasons.” Afterward, Girardi said “I’m not sure” regarding Headley’s availability for today.