Cobb scattered three hits, fanning four and walking two, but it was Rivera who stole the limelight late on, recording four outs before receiving a standing ovation from the Yankee Stadium crowd.
Evan Longoria drove in three while James Loney had three of Tampa's 11 hits as the Rays cut their wildcard magic number to two.
The Cleveland Indians stayed one game behind the Rays as they held off a startling ninth-inning rally from the Minnesota Twis to win 6-5.
Yan Gomes had three hits including a homer as the Indians established a 6-1 lead, but the Twins made things interesting by taking four runs off Cleveland closer Chris Perez, including Josmil Pinto's two-run shot.
Jurickson Profar launched a walk-off solo homer as the Texas Rangers beat the Los Angeles Angels 6-5 to stay within a game of the Indians.
Craig Gentry had three hits for the Rangers and Leonys Martin drove in two on a pair of hits.
Jason Heyward's lead-off homer sparked a five-run first as the Atlanta Braves moved back into a tie for the National League's best record with a 7-1 win over the Philadelphia Phillies.
Evan Gattis had three RBIs for the Braves, took control in the battle for homefield advantage thanks to their 4-3 season record against the St Louis Cardinals.
The San Diego Padres walked off with a 3-2 win over the Arizona Diamondbacks thanks to Alexi Amarista's 11th-inning RBI single, while the San Francisco Giants overcame the Los Angeles Dodgers by the same scoreline.
The Kansas City Royals beat the Chicago White Sox 3-2, the Milwaukee Brewers were 4-2 winners over the New York Mets and the Baltimore Orioles edged past the Toronto Blue Jays 3-2.