IT WAS a one-two punch.

First, the Boston Red Sox lost, then Evan Longoria, seemingly knowing what was on the line, lifted the Tampa Bay Rays into the playoffs.

The Rays clinched the AL wild card with a stunning rally last night, overcoming a late seven-run deficit, then beating the visiting New York Yankees, 8-7, on Longoria's home run in the 12th inning.

The Rays' win came 4 minutes after Boston blew a one-run lead in the ninth at Baltimore and lost, 4-3. The Red Sox, who held a nine-game lead over the Rays in early September, and Tampa Bay began the final day of the regular season tied for the wild card.

Longoria hit a three-run homer in the eighth that capped a six-run burst. Pinch-hitter Dan Johnson's two-out, two-strike solo homer in the ninth tied it for Tampa Bay.

Longoria won it with a one-out line shot barely inside the leftfield foul pole.

Tampa Bay will open the ALDS tomorrow at Texas.

The Red Sox, meanwhile, completed their September collapse in horrific and historic fashion. They held a nine-game lead in the AL wild-card race after Sept. 3, but a 7-19 swoon left them tied with Tampa Bay on the season's final day.

The Orioles won in the ninth against Boston closer Jonathan Papelbon (4-1), who struck out the first two batters before giving up a double to Chris Davis. Nolan Reimold followed with a double to score pinch-runner Kyle Hudson, and Robert Andino completed the comeback with a single to left that Carl Crawford couldn't glove.

Boston became the first team to miss the postseason after leading by as many as nine games for a playoff spot entering September, according to the Elias Sports Bureau.