ST. PETERSBURG, Fla. – Evan Longoria hit an RBI single in the bottom of the 11th inning, helping the Tampa Bay Rays rebound after blowing a ninth-inning lead to beat the Boston Red Sox 6-5 on Saturday night and pull within 4½ games of the AL wild-card leaders.

One week ago, the Red Sox had a nine-game lead in the wild-card standings over Tampa Bay.

Desmond Jennings opened the 11th with a triple off Daniel Bard (2-7) that lunging center fielder Jacoby Ellsbury couldn’t reach. After B.J. Upton hit a grounder to first, Longoria lined a single to center on an 0-2 pitch.

Brandon Gomes (2-1) worked 11/3 perfect innings for the Rays.

Jarrod Saltalamacchia and Ellsbury hit consecutive one-out solo homers in the ninth off closer Kyle Farnsworth to pull the Red Sox even at 5.

After Dustin Pedroia doubled and Adrian Gonzalez walked, Cesar Ramos replaced Farnsworth and induced a double-play grounder from David Ortiz.

Farnsworth has blown six saves in 29 opportunities this season, including two straight outings.

Gonzalez hit his 25th homer for the Red Sox, who have lost six of seven. Ellsbury has a 15-game hitting streak.

Boston left-hander Jon Lester (15-6) and Rays right-hander James Shields (14-10) are the scheduled starters in today’s series finale. Shields has 11 complete games this season, the most in the majors.

The teams begin a four-game series Thursday night at Fenway Park.

Tampa Bay went ahead 4-3 when Casey Kotchman hit a solo homer against reliever Alfredo Aceves in the fifth. It was Kotchman’s first homer since Aug. 12 off Yankees ace C.C. Sabathia.

Longoria made it 5-3 with a sacrifice fly in the sixth. He has driven in 63 runs over his last 71 games.

Gonzalez hit a two-run shot in the fifth that got Boston even at 3. Gonzalez had just seven hits — including one homer and two RBI — in his previous 45 at-bat against the Rays this season.

Jennings drove in a run on a grounder in the second inning, and Kotchman gave the Rays a 3-1 lead with a bases-loaded sacrifice fly one inning later.

Tampa Bay loaded the bases on two walks and a single with no outs in the first, but scored just once on Ben Zobrist’s grounder. Kyle Weiland avoided further damage by striking out Johnny Damon and getting a fly ball from Matt Joyce.

The Rays went 0 for 8 with runners in scoring position against Weiland, who allowed three runs, six hits and three walks over four innings.

Boston tied it at 1 on Jed Lowrie’s second-inning RBI grounder.

Tampa Bay rookie Jeremy Hellickson allowed three runs and five hits in six innings.

NOTES: Rays shortstop Sean Rodriguez set a club record when he was hit by a pitch for the 15th time this season in the sixth inning by Aceves. … The Rays plan to purchase the contract of utility player Russ Canzler and recall right-hander Dane De La Rosa from Triple-A Durham today. …

The Pawtucket Red Sox were eliminated from the International League playoffs Saturday, as the Lehigh Valley Iron Pigs completed a three-game sweep with a 3-1 victory. Alex Wilson allowed just three hits in seven innings but took the loss for Pawtucket.