MLB

Granderson, Yankees turn back Tigers’ rally with season-high 18 hits

UPS & DOWNS: Curtis Granderson, who had struggled in the leadoff spot, responded last night from the No. 6 spot, going 3-for-5 with a homer. (Getty Images)

DETROIT — Early it looked like a laugher. Later, it produced severe night sweats.

When the game ended, the Yankees had a crucial 12-8 win over the Tigers that was witnessed by a Comerica Park crowd of 41,879.

A six-run bulge after four innings with CC Sabathia on the mound should have been enough for the Yankees to stay away from biting their nails. But two Tigers runs in the sixth and four in a strange seventh — with the help of third baseman Casey McGehee’s crucial fielding error on Miguel Cabrera’s ground ball that should have been an inning-ending double play — turned it into an 8-7 game.

“I said to myself, ‘This is not happening,’ ” said David Robertson, who gave up four soft singles that produced three of the four seventh-inning runs that got the muscular Tigers back into the game. “What can you do?’’

Try scoring twice in the eighth against former teammate Phil Coke and an additional two off Brayan Villarreal in the ninth to secure the victory that went to Sabathia, who was somewhat surprisingly lifted with two outs in the seventh after having thrown 94 pitches.

Was Sabathia surprised he was taken out?

“A little bit,’’ Sabathia said. “But that’s why [Joe Girardi] is the manager and I throw the ball.’’

In 6 2/3 innings Sabathia (12-3) gave up five runs (three earned) and eight hits for his fifth straight victory.

BOX SCORE

“Delmon Young hits lefties better than righties and I thought it was time to go to Robbie,’’ was Girardi’s reasoning for turning to Robertson in the seventh.

The Yankees’ seventh win in 19 games stopped a two-game slide and enabled them to stay 4 1/2 games ahead of the second-place Orioles in the AL East.

“A lot of times you don’t care how you win, just win it,’’ Girardi said. “Especially at this time of the year.’’

The 18 Yankees hits were a season-high and every spot in the lineup produced at least one hit.

Curtis Granderson, who had been 2-for-20 as the leadoff hitter and hitless in 11 at-bats, was dropped to sixth and responded with a 3-for-5, four-RBI night that included his 30th homer.

“I just didn’t miss [pitches] tonight, nothing changed,’’ said Granderson, who was 0-for-5 Tuesday night and made the final out of a 6-5 loss.

Eric Chavez remained hot, going 2-for-4 and driving in two runs. In his last eight games Chavez is hitting .462 (12-for-26) with three homers and eight RBIs.

Robinson Cano had three hits and was drilled by a pitch from Anibal Sanchez in the third inning, producing a warning to each manager and to Sanchez from umpire Tim Welke.

After Mark Teixeira was hit by a Sanchez pitch in the first, Sabathia hit close friend and former teammate Prince Fielder with a pitch in the home first.

“He was trying to be proactive and making sure nothing happens,’’ Girardi said of the veteran umpire.

Following Tuesday night’s loss, Chavez said anybody who explained they weren’t concerned was lying.

“We were losing, if anybody was comfortable. … We had a nine-game lead [actually 10] and that’s gone,’’ Chavez said. “I just want to win and get back to the postseason.’’

Wins will get a team to October. No matter how ragged they look in August.

george.king@nypost.com