DETROIT - David Price allowed a homer to start the bottom of the ninth inning — and that was only the beginning of his problems as he tried to close out a win.

Rain began falling steadily at Comerica Park, a streak of lightning flashed in the sky behind centre field and loud thunder claps accompanied the Tampa Bay All-Star's pursuit of a complete game.

"It was crazy. I wasn't really looking up," manager Joe Maddon said. "Just trying to get David through it."

Eventually, Maddon gave in, removing Price with two on and two out. The Rays held on for a 7-3 victory over the Detroit Tigers on Sunday night to climb out of last place in the AL East.

The Rays have won three straight and eight of nine to move a half-game ahead of defending champion Boston in the standings. Tampa Bay had sole possession of the cellar for 39 consecutive days.

Price (8-7) received his fourth All-Star selection before the game, and he allowed three runs and seven hits before being pulled amid a brief spell of bad weather in the ninth. Jake McGee came on and got the final out for his fifth save in six chances.

Rick Porcello (11-5) allowed seven runs and 11 hits in 5 2-3 innings.

Matt Joyce and Desmond Jennings homered for Tampa Bay, and Torii Hunter and J.D. Martinez went deep for Detroit. The Rays had 19 hits, including four each by Ben Zobrist and Sean Rodriguez.

Price struck out six and walked three, throwing 107 pitches. Martinez led off the Detroit ninth with a homer, and Price was able to get only two more outs.

Price said he was somewhat fortunate to make it that far.

"I guess I got 26 outs, and I would say at least 15 of them were hit right on the screws. I was asking for some 'at 'em' balls yesterday and I got them," he said. "I don't know if I've ever seen that many hard-hit balls turned into outs off a starter."

The AL Central-leading Tigers put three players on the All-Star team — Miguel Cabrera, Victor Martinez and Max Scherzer. Porcello is a candidate in online voting for the final American League spot.

"Very happy for my teammates that have made the team, and obviously honoured to be included in the final vote," Porcello said. "A lot of good pitchers out there."

Porcello was coming off back-to-back shutouts, but his 25-inning scoreless streak ended before he could retire a batter. Jennings led off with a double and scored on Zobrist's single. Then Joyce's drive was ruled a home run after a review — it hit the railing just above the wall in right field — to give the Rays a 3-0 lead in the first.

Price went at least eight innings for the fifth time in his last six starts. It was his 15th straight outing of at least 100 pitches.

Price could be a prime trade target for contenders over the next few weeks, although Tampa Bay's recent run means the Rays aren't totally out of post-season contention. Tampa Bay is 8 1/2 games behind first-place Baltimore in the AL East, and the Rays trail Seattle by the same margin for the second wild card.

The Tigers, meanwhile, still lead their division by four games after losing three of four to Tampa Bay.

With Price on the mound, the Rays were in good shape after scoring three runs in the first. In the fifth, Evan Longoria added an RBI single to make it 4-1.

Tampa Bay scored three more in the sixth. With men on first and third and one out, Kevin Kiermaier hit a grounder to second that was nearly a double play, but he beat the relay to first for an RBI fielder's choice.

That made it 5-1 and kept the inning going. Jennings followed with a homer to left-centre.

Jennings also made sliding catches in centre field in the sixth and seventh.

Hunter led off the seventh with a solo shot, his 11th homer of the year. Detroit might have scored another run that inning on Austin Jackson's line drive to the corner in left. But Eugenio Suarez, trying to score from first, lost his footing on the grass outside the baseline and fell about halfway between third and home, giving the Rays an easy out at the plate.

NOTES: The Rays said after the game RHP Jeremy Hellickson (right elbow surgery) is expected back Tuesday. ... Victor Martinez sat out a second straight game with a back issue. ... Tampa Bay LHP Cesar Ramos and wife Melanie celebrated the birth Saturday of Addison Lynn Ramos, their first child. ... Rays SS Yunel Escobar (right shoulder) begins a rehab assignment Monday in the Gulf Coast League. ... Detroit is off Monday. Tampa Bay hosts the Royals. Rays RHP Jake Odorizzi (4-7) takes on Kansas City RHP James Shields (8-4).