Joe Girardi didn’t exactly lay out a complex formula for what the Yankees need in the second half to make a run.

Better starting pitching, better offense, better middle relief.

In their first game after the All-Star break — which began an important 10-game homestand against quality teams that Girardi didn’t try to undersell — two of those elements resembled what they were during the first half of the season.

For those not paying attention, that’s not a good thing.

Getting another poor outing by Michael Pineda and producing nothing against knuckleballer Steven Wright until the sixth inning, the Yankees fell to the Red Sox, 5-3, on Friday night in front of 47,439 at the Stadium.

advertisement | advertise on newsday

It is the first time since 1995 that the Yankees (44-45) have been below .500 after the All-Star break, and it only increased their sense of urgency. Said Girardi, “Of course there is, we’ve talked about it . . . because you start to run out of days.”

Pineda (3-9, 5.56 ERA) allowed five runs and five hits, including three home runs, in five innings-plus. Ryan Hanigan hit a solo homer and Travis Shaw and Xander Bogaerts added two-run shots against Pineda, who has allowed 18 home runs in 100 1⁄3 innings this season. “He missed his spots with his fastball and it cost him a couple of home runs,’’ Girardi said. “It comes down to location. It’s just not executing the way he needs to. You have to make better pitches.”

Could Pineda lose his rotation spot? “It’s who we have,’’ Girardi said, “so he’s got to get it done.”

Pineda retired the first eight batters before Hanigan homered to left-center on a 3-and-1 fastball that came in at 94 mph and straight. It was the first homer of the year for Hanigan, who had a .189/.250/.230 slash line.

In the fifth, Pineda issued a leadoff walk to Jackie Bradley Jr. and fell behind Shaw 3-and-1 before grooving a 93-mph fastball. Shaw’s 10th homer made it 3-0. After a leadoff single by Dustin Pedroia in the sixth, Bogaerts’ 11th homer gave Boston a 5-0 lead and ended Pineda’s night.

Yankees videos

Chasen Shreve, Nick Goody, Nathan Eovaldi and Aroldis Chapman held the Red Sox (50-38) to three hits and no runs in the last four innings, but Boston outhit the Yankees 8-4.

Wright was perfect through 4 2⁄3 innings before Alex Rod riguez reached on an infield single. Wright allowed one hit through five innings before losing command of his knuckleball.

With the Red Sox leading 5-0, Starlin Castro led off the sixth with a single and Chase Headley was hit by a pitch. Brett Gardner popped out, but Jacoby Ellsbury walked to load the bases and Carlos Beltran ripped a two-run single off first baseman Hanley Ramirez’s glove to make it 5-2. It gave Beltran, 39, a team-best 58 RBIs in 84 games and 1,501 in his career, making him the 46th player to reach that plateau.

Brian McCann then grounded a potential double-play ball to Ramirez, who made a weak, one-hop throw to second for the forceout as a run scored.

“He’s been good all year,’’ Rodriguez said of Wright. “I thought we had some good swings, some good approaches that one inning we scored three runs, but with a guy like that, you’re probably just going to get one crack at him, and tonight we just had one.”

advertisement | advertise on newsday

Brad Ziegler pitched a perfect seventh and Robbie Ross Jr. added a scoreless eighth. Koji Uehara closed with a perfect ninth.

Are the Yankees running out of time? “It’s one game,’’ Beltran said. “Tomorrow we have an opportunity to hopefully tie the series against [Eduardo Rodriguez] and hopefully be capable of winning the series. Right now we have to focus on winning series, especially against teams that are in our division. We’re playing Boston, the next team will be Baltimore, four games here are huge, so we have to get it done.”