Updated

Mariano Rivera took the mound in the eighth inning in his final appearance at Yankee Stadium, albeit not in the situation neither he nor his team had preferred.

Alex Cobb turned in a third straight brilliant start and Evan Longoria knocked in three runs on a pair of singles as the surging Tampa Bay Rays spoiled Rivera's home farewell with a 4-0 triumph over the New York Yankees.

"There's no better time," said Longoria. "I didn't think today could go any better for us in terms of the outcome of the game."

Cobb (11-3), the reigning American League Player of the Week, held the sputtering Yankees to three hits and two walks over seven-plus innings to lead the Rays to a seventh consecutive victory and move closer towards sewing up a postseason berth. Tampa Bay remained one game ahead of Cleveland for the AL's top wild card spot and two ahead of Texas.

Delmon Young added a solo home run while finishing 2-for-3, and James Loney went 3-for-3 with a run scored to help the Rays sweep the three-game set.

Rivera, whose 19-year career with the Yankees will officially come to a close following this weekend's upcoming series in Houston, retired all four batters he faced after coming on with one out in the top of the eighth. He was removed with two outs in the ninth, with longtime teammates Derek Jeter and Andy Pettitte coming to the mound to embrace baseball's all-time saves leader before he walked off to a standing ovation.

"Just a great moment," said Pettitte. "It was awfully cool. Its gonna be something that, obviously, I'll never forget."

Ivan Nova (9-6) pitched the first seven innings for New York and was touched for two runs on eight hits.

Cobb allowed a single to Eduardo Nunez in the first inning and walked Curtis Granderson in the second, then proceeded to set down the next 15 New York hitters until issuing a walk to Robinson Cano with one out in the bottom of the seventh and the Yankees down by a 2-0 count.

Longoria increased the margin further with a single up the middle in the top of the eighth that brought home Ben Zobrist and Loney, who had reached via a single and double, respectively, against reliever Dellin Betances.

Rivera entered to a rousing ovation with two on and one out in the eighth and recorded two quick outs to prevent further damage. The cheers grew louder after the legendary closer retired the first two hitters in the ninth and Jeter and Pettitte stepped out of the dugout. Following a warm exchange between the three Yankee greats, Rivera walked to the dugout in tears before ultimately collecting himself and stepping back onto the field for a curtain call.

"I wouldn't call it magical, I will call it blessed," said Rivera. "My opportunity to play for 19 years and give the best of my talents and my ability to this organization. The fans were there, I definitely appreciate that."

Aided by a pair of early double plays, Nova held the Rays scoreless over the first three innings before Tampa Bay broke through with a run in the fourth. A Wil Myers single and a walk to Loney put two on for Longoria, who ripped a single to left to plate Myers for a 1-0 lead.

The Rays later loaded the bases with just one out, but Nova was able to keep it a one-run differential by getting Matt Joyce to pop up in front of Jose Lobaton's inning-ending flyout.

It remained a 1-0 game until Young began the seventh with a blast that easily cleared the wall in left-center field.

The Yankees threatened to draw closer in their half of the eighth, as Granderson belted a leadoff double and Lyle Overbay singled to chase Cobb and place runners at the corners. Joel Peralta preserved the shutout, however, by striking out Zoilo Almonte and Vernon Wells in succession and getting J.R. Murphy to fly out.

Game Notes

The Rays reached the 90-win mark for the fourth consecutive season, the longest active streak in the majors ... Cobb has yielded just three runs over 23 1/3 innings in winning his last three starts, while fanning 26 batters during the stretch ... Tampa Bay took 12 of 19 meetings in the season series and outhomered the Yankees by a 26-9 margin, the largest ever by a single opponent against New York ... Nunez's single extended his hitting streak to seven games ... Rays shortstop Yunel Escobar did not start for a second straight game due to an ankle injury, but came in as a defensive replacement in the seventh inning ... The Yankees announced that Pettitte will have his final major league start pushed back until Saturday's game against the Astros.