KANSAS CITY, Mo. -- Nobody can say the Tampa Bay Rays backed into the AL East title Sunday.

Knowing that New York's loss about an hour earlier had already assured them of the championship, the Rays rallied for a 3-2 victory over Kansas City in 12 innings, sending them into the postseason on a winning note.

"Winning in extra innings on the road is a great measure of your team and the character of your group," Tampa Bay manager Joe Maddon. "Under these circumstances that really demonstrates that."

Tampa Bay will start the playoffs at home Wednesday against AL West champion Texas and have home-field advantage throughout the AL playoffs. The Yankees are the wild card and open Wednesday at AL Central champion Minnesota.

The Yankees and Tampa Bay began the day tied at 95-66, with both teams already assured of postseason spots. To win the division, New York needed to finish ahead of the Rays, who held the tiebreaker after winning the season series 10-8.

Carlos Pena hit a tying, two-run double in the ninth for Tampa Bay off All-Star closer Joakim Soria.

Pinch-hitter Rocco Baldelli singled with one out in the 12th off rookie Dusty Hughes (1-3) and stole second. Baldelli scored when Kelly Shoppach hit a grounder through the legs of third baseman Wilson Betemit, who was charged with an error.

When closer Rafael Soriano finished off the Royals for his AL-leading 45th save in 48 chances, the Rays streamed onto the field to celebrate.

"We knew the Yankees had not won," Maddon said. "This game at that point didn't mean a whole lot except it meant a lot to us to win it and to do it this way. Just to validate the whole thing."

The Rays are not exactly barreling into postseason on a hot streak. Since clinching a postseason berth Tuesday with a 5-0 victory over Baltimore, the Rays are 2-5 and have scored only nine runs. In their last seven games, they were shut out three times.

"This team is number one. That's why we have this chemistry," Pena said. "We have a lot of heart. Everybody cares about each other. I think that is extremely powerful. That's the intangible that goes a long way."

As the Royals kept shutting down the slumping Rays throughout a cool and breezy afternoon, Tampa Bay players kept one eye on the scoreboard and were heartened to see Boston slowly pulling away from the Yankees for an 8-4 victory.

Alex Gordon's two-run homer off Wade Davis gave the Royals a 2-0 lead in the fourth and Soria came on to try for his 44th save in 46 opportunities.

But the right-hander gave up a leadoff single to Carl Crawford and a one-out single to Matt Joyce before Pena's double into the left-field corner. It was Soria's first blown save since May 6 and the first runs he had allowed in 24 straight innings.

"To rally against their All-Star closer shows how much fight this team has," said Rays outfielder B.J. Upton, drenched just like the rest of his teammates in sweet-smelling champagne. "That shows how much heart this team has."

When they saw the Red Sox had beaten the Yankees, the Rays high-fived in the dugout, but did not go into any demonstrative celebration.

"We wanted to win this game," pitcher Joaquin Benoit said. "We still had work to do."

Jeff Niemann (12-8) struck out all three batters he faced in the 11th to earn up the victory.

Davis went seven innings and was charged with two runs on three hits, while striking out six.

The Rays loaded the bases in the second, but failed to score as Sean O'Sullivan struck out Dioner Navarro to end the inning. O'Sullivan held the Rays to two hits in six scoreless innings.

Game notes

The Rays tied a major league record Saturday night by using eight pitchers in a nine-inning shutout. ... Mitch Maier made a diving catch of Joyce's sinking liner to right field in the fourth.