The Astros stood along the railing of their dugout Sunday at Yankee Stadium out of Re2pect to No. 2 on Derek Jeter Night, watching the ceremony to retire his number and unveil his plaque. Carlos Beltran even popped out to present his former teammate with a members-only blazer for the Monument Park club.

Then the game started, and Houston didn’t show much respect to No. 19 of the Yankees, Masahiro Tanaka.

After the Yankees rallied to win the opener of the doubleheader, 11-6, the Astros pounded Tanaka for three homers and six runs in the first inning of the night shift. That escalated quickly. Alex Bregman capped the barrage with his first grand slam.

Tanaka served up two homers to George Springer in two innings and allowed eight runs and seven hits before Joe Girardi came out for a mercy pulling with two outs in the second. Houston held on to win the second game, 10-7, giving the team with MLB’s best record three wins in the four-game measuring-stick series.

“It wasn’t how we wanted this series to go,” Girardi said, “but to me we had a chance in three of the four games.”

Tanaka flashed a bad sign when Springer opened the game with a drive to Monument Park. Tanaka flashed another when Josh Reddick blasted the next pitch off the facing of the second deck in right.

advertisement | advertise on newsday

Bregman, who wears No. 2 in honor of Jeter, sent a souvenir to the bleachers in left for the 6-0 cushion.

“It was an unbelievable moment, unbelievable experience,” Bregman said. “It’s an honor to be playing in this game today. Just to be able to witness that whole ceremony was really cool and I’ll never forget it.”

Springer opened the second with a homer to right-center. And when Beltran hammered a two-out RBI double off the right-center wall, it was 8-0. Tanaka, now 5-2 with a 5.80 ERA, got booed off the mound. His breaking pitches were just flat.

“I didn’t do my job,” Tanaka said through an interpreter. “They have all the right to boo me.”

It was 9-0 before Charlie Morton (5-2) gave up four runs in the fifth, the last three on Matt Holliday’s seventh homer. Morton struck out 10 in 5 2⁄3 innings.

Yankees videos

The day shift went better for the Yankees (22-13).

The Astros (26-12) grabbed a two-run lead with a three-run top of the seventh.

The Yankees countered with a six-run bottom half highlighted by a tiebreaking three-run triple by a slump-ridden Chase Headley. They were on their way to their 10th comeback victory.

“There’s no panic,” Headley said. “Obviously, there’s some urgency . . . Obviously, when you’ve done it before, I think it gives you confidence that you can do it again.”

Brett Gardner got the seventh going for the Yankees with a one-out single off Will Harris (1-1). Jacoby Ellsbury doubled Gardner to third.

advertisement | advertise on newsday

Holliday singled to cut the Yankees’ deficit to 6-5. Chris Devenski replaced Harris and Starlin Castro greeted him with a double to tie it 6-6.

Aaron Judge, who hit his 14th homer in the first game, was intentionally passed, loading the bases. Didi Gregorius then struck out on three pitches.

So Headley stood in at 1-for-his-last-24. He lined a ball to right-center that rolled all the way to the wall to give the Yankees the lead for good at 9-6.

“It was pretty important not only for myself but the team,” Headley said.

Chris Carter followed with a line double to left to make it 10-6.

advertisement | advertise on newsday

Luis Severino started and lasted just 2 1⁄3 innings, allowing three runs, six hits and three walks. Adam Warren (1-0) got the win despite allowing those three runs in the seventh before the Yankees rallied.

But the Astros ultimately left the Stadium feeling satisfied. “We’ve been playing some good baseball,” Bregman said. “We have a good thing going here.”

Notes & quotes: This was the first-ever doubleheader between the teams . . . General manager Brian Cashman on first baseman Greg Bird (bruised right ankle): “Until he’s pain-free, there is no next step.” . . . Judge’s solo homer in the first game, which followed Castro’s two-run shot, was a 441-foot solo rocket off the facing over the black glass side of the restaurant beyond Monument Park — his sixth of at least 435 feet, which leads the majors.