Alex Cobb's worst inning in a long time started with Derek Jeter's first hit in a long time.

Jeter ended an 0-for-28 slump, the second-longest hitless streak of his career, and the New York Yankees beat the Tampa Bay Rays 3-2 Wednesday night in his last game at Tropicana Field.

Cobb (9-8) gave up the hit to Jeter in the sixth inning, and the retiring captain eventually scored on Brett Gardner's bases-loaded sacrifice fly.

Cobb threw 39 pitches in the inning. He had not given up as many as three runs in 12 consecutive starts going back to July 4 - the streak tied for third-best by an AL pitcher in 100 years.

Cobb allowed three runs and four hits over six innings, and was somewhat relieved not to give up more. Right fielder Wil Myers had to jump to catch Gardner's fly near the top of the wall.

"Wil probably saved me three runs," Cobb said. "Gardner just missed a grand slam there, so you walk away from it pretty fortunate. But in the middle of all that (I had a) loss of command."

Cobb tied a career high with three walks in the long inning, but his problems started in the preceding inning when he hit Chris Young with a curveball.

A day earlier, Jeter was hit on the left hand by Steve Geltz in the eighth, then Yankees reliever David Phelps was ejected in the bottom half for throwing a tight pitch to Kevin Kiermaier.

This time things remained calm.

"I heard the boos," Cobb said, "but that's just unknowledgeable baseball fans, if I dare go there."

The Yankees broke through with two runs in the fifth, however, and that's where Cobb's troubles began.

"Cobb was in great shape prior to that inning . . . from the moment he hit Young with the breaking ball, his overall command was a little different," Rays manager Joe Maddon said. "I'm just talking mechanically, he was off, and after that I just saw him not as sharp as he had been prior to that."

Brandon McCarthy (7-4) allowed two runs and four hits in seven innings. Dellin Betances and David Robertson, who got his 37th save, completed a five-hitter.

Evan Longoria hit a solo home run and had RBI grounder for the Rays. He has 46 RBIs in 56 games since the All-Star break.

Chase Headley and Brendan Ryan hit run-scoring doubles in the fifth that put the Yankees up 2-1.

Alan Porter was the plate umpire in place of Joe West, who was suspended for one game without pay for grabbing the jersey of Philadelphia closer Jonathan Papelbon on Sunday. Sean Barber joined the crew and was at third base.

JETER METER

Jeter, who lives in nearby Tampa, went 1 for 4 and scored a run in his 126th game at Tropicana Field. The hit was his 145th at the stadium and the run was his 80th - those numbers are highs by a visitor.

Jeter got a loud ovation from the announced crowd of 26,332 before grounding out in his last at-bat in the seventh.

TRAINER'S ROOM

Yankees: 1B Mark Teixeira (sore right wrist) played after missing Tuesday's game. ... DH Carlos Beltran, who left the team Tuesday, posted on Facebook that he and his wife had lost their unborn son.

"It puts things in perspective," Jeter said. "The bottom-line, family is most important."

HIGH AND TIGHT

Six New York batters have hit by a Rays pitcher in the past week. Yankees manager Joe Girardi is unhappy that some of them came on high pitches.

"When you talk about pitching high and inside, I mean there's elevated `in' and then there's throwing up at somebody's head," Maddon said. "But believe me, man, I would never tell the Yankees how to train their pitchers."

UP NEXT

Yankees: Jeter starts his final homestand Thursday night. RHP Shane Greene (5-3) and Toronto knuckleballer R.A. Dickey (13-12) are the scheduled starters.

"I don't really know," Jeter said on what his final games at Yankee Stadium will be like. "I try not to anticipate anything. We'll find out."

Rays: Tampa Bay begins its final home series of the season Friday night against the Chicago White Sox.

© 2014 The Associated Press. All rights reserved. This material may not be published, broadcast, rewritten or redistributed. Learn more about our Privacy Policy and Terms of Use.