NEW YORK — Raul Ibanez lined a tying home run while pinch hitting for slumping Alex Rodriguez in the ninth inning, then hit a leadoff homer in the 12th, giving the New York Yankees a stunning 3-2 win over the Baltimore Orioles on Wednesday night for a 2-1 lead in their AL Division Series.
Batting for baseball’s highest-paid player, Ibanez homered to right-center with one out in the ninth inning off major league saves leader Jim Johnson to make it 2-2. He connected on the first pitch from Brian Matusz in the 12th.
Ibanez became the first player to homer twice in a postseason game in which he didn’t start, STATS LLC said.
Phil Hughes will try to clinch it for the Yankees on Thursday night in Game 4 of the best-of-five series. Joe Saunders will start for Baltimore.
Baltimore had won 16 straight extra-inning games, and had been 76-0 when leading after seven, before the Yankees stung them.
‘‘It was a great experience. We do it as a team. We stay after it,’’ Ibanez said. ‘‘I'm blessed to come up and have the opportunity like that. We do it together. it’s about a team and about winning.’’
Ibanez got that chance after Yankees manager Joe Girardi made the decision to bat for Rodriguez — the first time A-Rod had ever been pinch-hit for in a postseason game, according to STATS.
Yankees fans had been calling this week for Girardi to get Rodriguez out of the No. 3 spot in the batting order. But Girardi was reluctant to move his fading slugger down in the lineup.
Until he toook him all the way out.
‘‘You have to make some decisions sometimes that are tough decisions. I just had a gut feeling,’’ Girardi said.
Rodriguez has 647 career home runs — he’s chasing the all-time record of 762 by Barry Bonds — but was just 1 for 12 with no RBIs and seven strikeouts in this series when Girardi pulled him.
‘‘He said, ‘Do what you got to do,’ ’’ Girardi said, recalled Rodriguez’s reaction.
‘‘You’re going to be asked a lot of questions if it doesn’t work,’’ the manager said.
The brash, young Orioles appeared poised to move within a game of their first trip to the AL Championship Series since 1997.
But Ibanez hit a 1-and-0 pitch into the seats in the ninth, setting off a raucous celebration in what had been a demoralized Yankee Stadium crowd. Rodriguez led the cheers, raising an arm in the dugout. and high-fiving injured star Mariano Rivera.
‘‘He said great job. A-Rod is a great teammate and great team player,’’ Ibanez said. ‘‘He’s the first one on the top step congratulating you. It’s about winning. It’s about the Yankees and continuing.’’
New York won the opener in Baltimore scoring five runs in the ninth off Johnson. The Orioles won Game 2 and rode Miguel Gonzalez’s pretty performance to a 2-1 lead in the ninth.
But the Yankees limited Baltimore to one hit after Manny Machado homered in the fifth. Ryan Flaherty homered earlier for the Orioles.
Robert Andino was doubled off second after leading off the Baltimore ninth with a single and advancing on a sacrifice.
Boone Logan got one out in relief of Hiroki Kuroda, who gave up two solo homers in 8⅓ innings. Closer Rafael Soriano pitched 1⅓ innings and David Robertson went two, finishing off his outing by bumping into and tagging Andino to end the top of the 12th.
Derek Jeter tied the score with an RBI triple in the third for the Yankees. Jeter, limping because of a sore ankle, came out after eight innings.