PHOENIX — Eighteen straight retired, 85 pitches.

That was Nathan Eovaldi through six innings Wednesday night, the righthander still firing fastballs occasionally touching 98 mph, his splitter and slider as good as they’ve been all season, and a 3-1 lead.

But with his full complement of seed-throwing relievers available at the back end of the bullpen, Joe Girardi went to them.

It nearly blew up in his face but, after jittery moments from both Dellin Betances and Andrew Miller, the Yankees escaped with a 4-2 victory in front of 32,191 at Chase Field to avoid what would have been an embarrassing sweep.

“I’m going to take my chances probably 99 percent of the time with Betances, Miller and Chapman,” said Girardi, whose team improved to 17-22 and starts a four-game series in Oakland Thursday night. “Just because they’re so good.”

The 26-year-old Eovaldi, inconsistent much of the season – like every rotation member – allowed a leadoff double and nothing else over six brilliant innings, retiring 18 straight thereafter.

advertisement | advertise on newsday

“I thought I was going back out,” Eovaldi said. “I was a little disappointed, but you’ve got those three guys coming in so you can’t be too frustrated about that.”

Only a fielding blunder by Chase Headley in the first allowed a run to come across as Eovaldi allowed one run and one hit over six innings, striking out five.

“He’s capable of really being something special, a lot better than he’s shown at times,” said Brett Gardner, whose two-run homer in the first gave Eovaldi a 2-0 lead. “I thought tonight was as good as I’ve seen him.”

Yankees videos

Eovaldi, now 4-2 with a 4.44 ERA, gave way to Betances, who nearly had the torch-and-pitchfork crowd looking for Girardi when he walked the first two batters, Phil Gosselin and Paul Goldschmidt, he faced.

But Betances struck out Jake Lamb, after falling behind 2-and-0, and quickly retired the side.

“I was just trying to make the people sweat a little bit back home,” Betances joked.

Andrew Miller allowed a leadoff homer to Chris Owings in the eighth to make it 3-2, but struck out three straight.

After Evan Marshall threw a wild pitch with the bases loaded with two outs in the ninth to make it 4-2, Aroldis Chapman struck out one in a perfect ninth to notch his fourth save in four tries.

advertisement | advertise on newsday

Arizona righthander Shelby Miller, who came in 1-4 with a 6.94 ERA and having walked more batters (23) than he’s struck out (22), allowed three runs and 10 hits over 5 2/3 innings.

Jacoby Ellsbury, who went 3-for-3 with two walks, led off the game with a walk and came in on Gardner’s fifth homer of the season.

Eovaldi had some bad luck and poor fielding go against him in the bottom half as the Diamondbacks (19-24) cut it to 2-1.

Jean Segura, 4-for-9 the first two games of the series, led off with a slow bouncer up the middle that bounced off the second base bag and into center for an interesting-looking double. Gosselin’s groundout to second moved Segura to third and Paul Goldschmidt, 3-for-7 with a homer and three runs the first two games, followed with a grounder to third. Segura hesitated going down the line and almost seemed surprised when Headley didn’t give him more than a cursory glance back. Segura continued home and scored as Headley – mentioned earlier in the day along with Mark Teixeira, Michael Pineda and Luis Severino by managing general partner Hal Steinbrenner as the major causes of the club’s rough start – nipped Goldschmidt at first.

The Yankees, who stranded six over the first five innings, finally added on in the sixth on Ellsbury’s two-out RBI single that brought in Headley to make it 3-1.

advertisement | advertise on newsday

“It was a nice night go kind of get the offense going,” Ellsbury said. “Tonight was obviously an important win for us to give us a little momentum going to Oakland.”