DETROIT — Joe Girardi got mad.

Then, the New York Yankees got even.

Mark Teixeira and Eric Chavez hit solo home runs on consecutive pitches in the eighth inning that put New York ahead after Girardi was ejected, and the Yankees held off the Detroit Tigers 4-3 Thursday to split a four-game series.

“I’m extremely happy for what our guys accomplished,” Girardi said, still stewing after the victory. “That doesn’t mean I’m not going to get perturbed when I get a letter.”

Girardi was tossed in the fifth during a demonstrative argument in which he slammed his hat on the infield and threw his arms in the air over and over, repeating a move third base umpire Tim Welke acknowledged making on a fair-or-foul call.

“It’s good that he’s sticking up for us,” Yankees catcher Chris Stewart said. “It fired us up, obviously.”

The Yankees won a one-run game for the first time since July 13, ending an eight-game losing streak in one-run games that was their longest since 1944.

“It’s just nice to get a win — period,” Stewart said. “We’ve been scuffling lately and things haven’t been going our way. It almost seemed like it was going to happen again.”

Rafael Soriano escaped a first-and-third, no-out jam in the ninth for his 27th save in 29 chances.

Alex Avila led off the ninth with a double and pinch-runner Gerald Laird advanced to third on Omar Infante’s single. Soriano got Ramon Santiago on a soft lineout, retired Quintin Berry on a popup and got Andy Dirks on a flyball.

“We let a golden opportunity get away there in the ninth,” Tigers manager Jim Leyland said.

Clay Rapada (3-0) got the last two outs with one on in the seventh inning.

Joaquin Benoit (1-3) retired the first batter in the New York eighth before Teixeira and Chavez connected, the eighth time the Yankees hit consecutive homers this season.

Teixeira hit a no-doubt line drive to right for his 21st homer. Chavez went to opposite field, clearing the left-field wall with his ninth homer in 35 games after hitting just three in his first 42 games this year.

Benoit has given up nine hits — seven for homers — in 10 games since the All-Star break.

“He hasn’t been keeping the ball in the ballpark very well,” Leyland said.

New York led early, and late, for a second straight victory after dropping the first two games in Detroit.

Girardi wasn’t in the dugout at the end of the latest win.

He became upset after Dirks hit a go-ahead double down the line because Welke put his hands up to indicate it was a foul ball, then signaled it was fair, and left fielder Raul Ibanez struggled to field the ball.

“I started to put my hands up in the air — I was a little quick — then I saw the ball hit the chalk line, and I pointed fair about three times,” Welke said. “I don’t think it had any impact. I’ve watched the replay, and I don’t think there was any impact on the outfielder. I don’t think Ibanez ever even saw me. We got the call right.”

Replays weren’t conclusive as it to where it landed

“I was surprised that he called it fair,” Ibanez said. “It was called foul.”

Girardi had to be separated from Welke more than once by second base umpire Bob Davidson during the long confrontation.

“Joe thought it was a protestable situation, but it was a judgment call,” Welke said. “He wanted to play the game under protest, and that was most of the discussion.”

As he walked off, Girardi gestured that Berry should go back to first base and Dirks should bat again. Girardi insisted he wasn’t playing to the crowd.

“That’s not my personality,” he said. “I was just still very perturbed.”

Girardi has been ejected three times this season, all against Detroit.

The Yankees scored twice with two outs in the second on Ibanez’s triple and Ichiro Suzuki’s single.

Alex Avila’s two-run homer tied it in the fifth and Dirks’ double put the Tigers ahead and led to Girardi being tossed.

Doug Fister allowed two runs on eight hits over 6-13 innings, giving the Tigers a shot to win only to have Benoit blow it.

“Any time you see a pitcher give up a hit, you feel for them,” Fister said. “You feel their pain, their struggle.”

New York starter Hiroki Kuroda gave up three runs and 10 hits, matching a season high, over 6 1-3 innings.

NOTES: The game started after a 29-minute rain delay and it started raining again in the middle of the game. .. New York’s road trip continues Friday night at Toronto. … Detroit, which went 5-2 on its homestand, plays Friday night at Texas. … Suzuki has at least a hit in 15 of 16 games with the Yankees. … The Tigers outrighted OF Don Kelly’s contract to Triple-A Toledo.