NEW YORK (AP) -- The perfect script.

Derek Jeter capped his Yankee Stadium farewell with a game-winning single in the bottom of the ninth inning, the latest - and perhaps last - storybook moment in his charmed and illustrious career, to give New York a 6-5 victory Thursday night over the Baltimore Orioles.

Serenaded with adoring chants that echoed through the Bronx night, Jeter tipped his cap several times at shortstop and drove in three runs. He launched an early double off the left-center wall and saved the best for last, a sharp, opposite-field single to right that knocked in the winning run.

During the raucous celebration that followed, Jeter said he's played his final game at shortstop, but he'll likely play in some capacity this weekend in Boston.

It appeared Jeter's tiebreaking grounder in the seventh would be the swing that sent the Yankees to a victory when they built a 5-2 cushion against the AL East champions.

Not bad - but not Jeter.

Nope, he's always had a flair for the most electrifying kind of drama, and this night was destined to be no different.

As if it was planned all along, closer David Robertson (4-5) gave up a two-run homer in the top of the ninth to Adam Jones and a tying shot to Steve Pearce with two outs.

That only set the stage for Jeter one more time.

Jose Pirela hit a leadoff single in the bottom of the ninth against Evan Meek (0-4) and advanced on Brett Gardner's sacrifice. Jeter lined the next pitch through a huge hole on the right side, and pinch-runner Antoan Richardson slid home ahead of Nick Markakis' throw.

An elated Jeter jumped and raised both arms between first and second. Yankees players rushed out to engulf him as former teammates such as Jorge Posada, Mariano Rivera, Bernie Williams, Andy Pettitte, Tino Martinez and Hall of Fame manager Joe Torre lined up near the New York dugout waiting to greet the retiring captain.

"It was above and beyond anything that I've ever dreamt of," Jeter said.

Jeter went back out to shortstop, crouched down at the edge of the outfield grass and bounced on his toes a couple of times before rejoining the group.

He tipped his cap again and was doused over the head with a sports drink by Gardner and CC Sabathia.

In one twist that hardly fit, Jeter's home finale was the only game he ever played at Yankee Stadium with his team already knocked out of the playoff race.

When the Yankees were eliminated with Wednesday's loss, it put all the attention Thursday entirely on the captain's farewell - a feeling that must have been unsettling even for a 40-year-old mega-star as accustomed to the spotlight as Jeter.

"He's uncomfortable with what's going on. He wants the focus to be on the team," said Orioles skipper Buck Showalter, who was Jeter's first manager when the shortstop broke into the big leagues in May 1995.

"His signature is winning. What other accolade can you pick? His teams won," Showalter said. "Take a good look, because there are not going to be many like this come your way again."

Jeter ended last season on the disabled list, so the only other time in his 20-year career (2,745 regular-season games) that he appeared in a game with New York already out of postseason contention was in Boston on Sept. 26, 2008.

Last year, Rivera chose to sit out the final three games in Houston after an emotional Yankee Stadium goodbye.

Heavy rain soaked the city all afternoon, but the sky cleared in the evening and the tarp was removed from the infield an hour before the first pitch. A rainbow, in fact, appeared over the stadium.

The game began right on time, but it didn't start well for the Yankees.

Roll call by the Bleacher Creatures was interrupted just as they got to a roaring chant of "De-rek Je-ter!" Markakis hit a leadoff home run for the Orioles, awkwardly silencing the sellout crowd of 48,613 that included rap star Jay-Z and other famous faces.

Alejandro De Aza followed with another long ball to right, the first time Baltimore had started a game with consecutive homers since hitting three in a row against Texas on May 10, 2012.

Jeter, however, hit an RBI double in the first against rookie Kevin Gausman, who was 4 years old when Jeter made his major league debut. The ball banged off the left-center wall -- just missing a home run by a couple of feet. He scored on a grounder, and the fans were back into it.

More From 1460 ESPN