Updated

Robinson Cano hit a tiebreaking leadoff home run in the ninth inning Wednesday and the New York Yankees held on to beat the Baltimore Orioles 5-4.

The win came hours after the Yankees announced star shortstop Derek Jeter was done for the season with an ankle injury.

Cano's homer on an 0-1 pitch from Tommy Hunter (4-4) just cleared the wall in center field. Lyle Overbay added an RBI single off Troy Patton to score Curtis Granderson -- an insurance run the Yankees needed after Mariano Rivera gave up a run in the bottom of the ninth.

Rivera allowed a two-out double to Nate McLouth, who scored on Brian Roberts' single before Rivera struck out Manny Machado to end the game and lock down his 43rd save.

"We get down tonight and come back again. We were able to take the lead in the ninth. We get a huge homer by Robbie and then a huge hit by Lyle that winds up being a lot bigger," Yankees manager Joe Girardi said.

Granderson and Alex Rodriguez also hit solo homers for the Yankees, who have won two out of three in the four-game series. Andy Pettitte went 6 1/3 innings and gave up three runs on nine hits. David Robertson (5-1) pitched the eighth and got the win.

Chris Davis hit a two-run double for the Orioles, who have dropped three of their last four. Like the Yankees, they are chasing an AL wild card spot.

Baltimore starter Scott Feldman gave up just three hits in 7 2/3 innings -- two were homers -- while striking out six and walking two.

Brett Gardner led off the game with a walk, stole second base and scored after back-to-back ground outs by Rodriguez and Cano to give the Yankees a 1-0 lead.

Roberts and Machado hit consecutive singles in the third inning and scored on Davis' double, putting the Orioles on top 2-1. They took a 3-1 lead in the third after Danny Valencia hit a leadoff double and scored on J.J. Hardy's one-out double to the wall in right-center.

Granderson's long solo homer leading off the fifth was the Yankees' first hit and pulled them within 3-2.

The next hit Feldman gave up was also a homer -- Rodriguez's two-out shot in the sixth that tied the game.

"He was really good again, especially when you take into consideration they've seen all he has to offer (in a start last month)," Orioles manager Buck Showalter said of Feldman. "That bodes well for some things he can do for us the rest of the way."

"We just had a little trouble keeping the ball in the park tonight," Showalter said.

The Yankees placed Jeter on the disabled list before the game and said his season was over despite a CT scan on his surgically-repaired left ankle coming back negative.

The Yankees were worried about the possibility Jeter might be injured further if he played again this season. The star shortstop fractured the ankle in Game 1 of last year's ALCS and played in only 17 games this season, batting .190 with one home run.

"This is what's best for Derek," Yankees general manager Brian Cashman said, according to MLB.com. "Something's going to give at some point the more we run him out there."

Game Notes

The Yankees designated pitcher Jim Miller for assignment to make room on the roster for Brendan Ryan, who was acquired from the Mariners on Tuesday. Ryan played short and was 0-for-4 ... Rivera recorded 79th career save against the O's, the most by any pitcher against any team in major league history ... Davis became the first player in Orioles' franchise history with 40 homers and 40 doubles in the same season.