BOSTON – The ball struck David Price in the chest and bounced in the air, a line drive that had a chance to devastate the Tampa Bay Rays’ playoff chances.

But Evan Longoria fielded the carom and threw to first for the out, Price stayed in the game, and Tampa Bay beat the Red Sox 8-5 on Sunday to take three out of four from Boston and close within two games in the AL wild-card race.

The Red Sox have lost 11 of their last 14 and are now left rooting for the New York Yankees, who play the Rays seven times in Tampa Bay’s last 10 games.

“To be able to do this against this team here, if that can’t bolster your confidence nothing really can,” Rays Manager Joe Maddon said. “Now it becomes more viable. You can see the light at the end of the tunnel, and now it’s not attached to an oncoming train.”

Tampa Bay already led 3-0 against a wild Tim Wakefield when Mike Aviles hit a hard shot up the middle and off the “Rays” logo below Price’s right shoulder. The ball bounced toward third base for a 1-5-3 putout, and trainers went to the mound to look at Price.

After several minutes of examination — at one point Price sat on the ground and untucked his shirt so the medical staff could look at the bruise — Price retired Adrian Gonzalez on an inning-ending groundout. Price later gave up Darnell McDonald’s two-run double in the fourth that made it 4-2.

Jake McGee (3-1) relieved and pitched 2 2/3 innings of relief for the win, and Joel Peralta closed out the game for his fifth save.

Price went to Massachusetts General Hospital for tests, which were negative, and team spokesman Rick Vaughn said he would join the team at the station for the train ride to New York.

Tampa Bay, which trailed Boston by nine games on Sept. 3, closed within two games of the wild-card lead for the first time since June. The Red Sox have 10 games left: seven against last-place Baltimore and three at Yankee Stadium; in addition to their seven against the AL East-leading Yankees, the Rays have three against Toronto.

Second baseman Dustin Pedroia noted that the Red Sox still had the lead.

“We’re winning. We’ve got to go out and play better. That’s basically it,” he said. “I’m real confident. We’ve got a great team and we’ve got to find a way to figure it out. We’ve got a two-game lead with 10 games to go. We’re not going to sit back and feel sorry for ourselves. We’ve got to win. I’ve already turned the page.”

Matt Joyce had three hits and three RBI and the Rays capitalized on Wakefield’s knuckleball to beat Boston for the eighth time in nine games.

Wakefield (7-7) threw one wild pitch and catcher Jarrod Saltalamacchia muffed four of his knucklers for passed balls, miscues that contributed to three runs.

Tampa Bay went ahead 3-0 in the second after Casey Kotchman led off by reaching on a passed ball on a third strike. He took second on another passed ball and scored on Johnny Damon’s double.

Wakefield allowed six runs — two earned — six hits, one walk, one wild pitch and a hit batter in five innings.

Andrew Miller added a wild pitch in the seventh that helped another run score. Aviles also had two throwing errors at third base, contributing to one more run.