Updated

ST PETERSBURG, Florida (Reuters) - The Tampa Bay Rays snatched the American League wild card playoff berth from the clutches of the Boston Red Sox with a stunning 12-inning home victory over the New York Yankees on the last day of the regular season on Wednesday.

The Rays looked down and out but wiped out a 7-0 deficit with six runs in the eighth and Dan Johnson's two-out homer in the ninth, before Evan Longoria's walk-off home run in the 12th sealed an unlikely 8-7 victory.

Longoria, who had capped the eighth-inning rally with a three-run home run, was mobbed at home plate after his walk-off shot down the left-field line off Scott Proctor for the win.

The stunning triumph combined with Boston's heart-breaking 4-3 loss in Baltimore enabled the Rays (91-71) to clinch the postseason berth and avoid a one-game playoff against the Red Sox (90-72) had the teams ended the regular season with identical records.

Boston had led the Rays by nine games in the first days of September before their nose-dive in the final weeks.

Tampa Bay's triumph came just moments after the Red Sox had squandered a 3-2 lead in the bottom of the ninth, when closer Jonathan Papelbon failed to secure victory after striking out the first two batters.

Chris Davis lined a two-out double down the right field line and Nolan Reimold followed with a ground-rule double to center to tie the game.

HIGH EXPECTATIONS

When Robert Andino lined a run-scoring single that charging left-fielder Carl Crawford narrowly failed to glove, the last-placed Orioles celebrated as if they had reached the playoffs.

"I'm disappointed," said Crawford, who signed a rich free-agent contract with Boston after stellar seasons with the Rays.

"I had high expectations of the season."

Papelbon added: "Whatever doesn't kill you makes you stronger. I've always been one to bounce back. We'll bounce back next year and go back after it again."

The Rays and Red Sox entered the final day of the 162-game season with 90-71 records. Had they both won or lost, they would have met in Florida on Thursday to see who would advance to the divisional playoffs.

"I was just so fortunate to get that chance and capitalize on it," said reserve first baseman Johnson, who had two strikes on him when he belted the game-tying pinch-hit homer in the ninth off reliever Cory Wade.

"This team is just a bunch of grinders. We just go out there and try to win every night. We just kept grinding it out."

Longoria said he had heard the Orioles had tied the Red Sox as he made his way to the plate in the 12th, and then figured Boston had lost when he heard the Tropicana Field crowd roar even louder.

"I can't really put it into words. We were out here for the better part of five hours and then it seemed like everything happened in matter of seconds," Longoria said after the four-hour 54-minute game against the AL-best Yankees.

(Reporting by Larry Fine; Editing by John O'Brien/Ian Ransom)