RONALD BLUM, AP Sports Writer

NEW YORK (AP) — Mariano Rivera said goodbye to Yankee Stadium with hugs, tears and cheers.

Baseball’s most acclaimed relief pitcher made an emotional exit in his final appearance in the Yankees’ home pinstripes, when captain Derek Jeter and Andy Pettitte came to the mound to remove him with two outs in the ninth inning of a 4-0 loss to the Tampa Bay Rays on Thursday night.

“It’s time to go,” Jeter appeared to tell Rivera.

Tampa Bay won its seventh straight and leads the AL wild-card race.

During four minutes of thunderous chanting from the sellout crowd 48,675, an overcome Rivera sobbed as he buried his head on the shoulder of Pettitte, who also is retiring when the season ends Sunday, and then hugged Jeter.

It was an extraordinary sight in a sport where a manager almost always goes to the mound to make a pitching change. Yankees manager Joe Girardi checked with the umpires to make certain Jeter, who is on the disabled list, could take part.

“I was so thankful they came out,” Rivera said after the game.

Rivera, who retired four straight batters, wiped his eyes with both arms as he walked off and blew a kiss to the first row behind the Yankees dugout. He hugged a tearful Girardi in the dugout, grabbed a towel to dab the tears, and came out again and doffed his cap to the crowd. All the while, the Rays remained in their dugout applauding.

Throughout the stands, fans blinked back tears.

When Rivera came off, Pettitte came out for his own curtain call as the Rays waited. After the last out, Rivera remained on the bench for a moment as “New York, New York” played.

The 43-year-old Rivera then took a final walk to the mound, where he stood, rubbed his feet on the rubber, kneeled and gathered dirt as a keepsake.

Rivera had entered with one out and two on in the eighth to a recorded introduction by Bob Sheppard, the longtime Yankees public address announcer who died three years ago.

Fans stood, applauded and chanted his name as he jogged in from the bullpen to Metallica’s “Enter Sandman” and continued for two minutes as he took his warmups. The entire Tampa Bay bench emptied and stood on the dirt warning track in front of the dugout and applauded.

Fans remained on their feet, chanting his name as he got two quick outs on six pitches. In his first appearance since the Yankees retired his No. 42 during a 50-minute ceremony Sunday, Rivera retired Delmon Young on a groundout and Sam Fuld on a comebacker.

He lingered on the dugout bench when the eighth inning ended and took in the whole stadium scene as he teammates ran onto the field. Rivera jogged out last and was given another standing ovation. With the crowd shouting at a postseason level, he retired Jose Lobaton on a comebacker and Yunel Escobar on a popup to second before the famous, final scene.

The Yankees, eliminated from playoff contention, finish the season with three games in Houston.

The oldest player in the major leagues, Rivera record 314 of his record 652 saves at home during a 19-year big league career, and 18 of his record 42 postseason saves were at the old and new Yankee Stadium.

Rivera helped the Yankees to five World Series titles, getting the final out in four of them.

Tampa Bay lowered to two its magic number over Texas for clinching an AL wild-card berth. The Rays swept this three-game series, outscoring the Yankees 19-3.

Alex Cobb (11-3) took a one-hit shutout into the eighth, retiring 15 in a row between walks to Curtis Granderson in the second and Robinson Cano in the seventh. He wound up allowing three hits in seven innings-plus.

Evan Longoria hit an RBI single in the fourth against Ivan Nova (9-6) and a two-run single off Dellin Betances in the eighth. Young hit a long solo homer to left-center in the sixth.

New York has lost nine of 12, including four in a row, and at 82-77 will have its fewest wins in a non-shortened season since

A night after the Yankees were eliminated from contention — missing the playoffs for just the second time in 19 years — it was a night for nostalgia. Rivera’s 42 — he’s the last player to wear Jackie Robinson’s old number — was painted in foul territory in front of each dugout.

Rivera, who announced during spring training that this would be his final season, was given his first standing ovation of the night when he met with Yankees employees in the interview room across the tunnel from the Yankees clubhouse. He lingered on the field during batting practice, signing autographs for fans. And just before the first pitching, there was another set of presentations at home plate — a daily fixture during the final homestand.

Chants of “Mar-i-a-no!” began three pitches in. Fans cheered every time Rivera and Pettitte appeared on the center-field video board, and sustained “Mar-i-a-no!” chants resumed when he started warming up in the bullpen in the top of the eighth. Fans screamed “We want Mo!” after Longoria’s single gave the Rays a four-run lead.

More honors are ahead this weekend, when the Yankees finish the season at Houston. The Astros plan a pregame ceremony Sunday that will include former New York manager Joe Torre and former Rivera teammate Roger Clemens.

NOTES: Matt Daley is sure to be the answer to a future trivia question — he was the pitcher who relieved Rivera. … Rivera had not entered a game with the Yankees trailing by four runs or more since May 20, 2008, against Baltimore, according to STATS. … The Yankees drew an AL-high 3,279,589, their lowest in five seasons at new Yankee Stadium and down from 3.54 million last year. Their average of 40,488 was their lowest since 40,346 in 2000, according to STATS. The Yankees had just seven sellouts. … New York hit 75 home runs at Yankee Stadium, its lowest home total since 75 in 1997. … Girardi wouldn’t comment on an ESPN report that Cano, who is eligible for free agency, is seeking a 10-year deal worth a record $305 million. … Bothered by sore legs, 3B Alex Rodriguez didn’t play. … Tampa Bay SS Yunel Escobar (sore left ankle) was in the original starting lineup, then was scratched. He entered in the seventh inning. … Rays manager Joe Maddon wasn’t sure whether RHP Jesse Crain (right shoulder strain) will pitch during the rest of the regular season.