ST. PETERSBURG, Fla. — As he aged, CC Sabathia learned how to successfully retire big league hitters with a variety of off-speed pitches to go with a fastball that had lost velocity.

Now with the sun setting on a Hall of Fame career, Sabathia is attempting to reinvent himself again — in a foreign role — with the hope of helping the Yankees win the World Series.

The Yankees haven’t announced their rotation plans for the ALDS, but it’s very clear that taking a look at Sabathia out of the pen in the final week of the season is an indication they believe he can help in that role.

So in the fourth inning Tuesday night at Tropicana Field, Sabathia entered from the bullpen in an eventual 2-1, 12-inning loss to the Rays that was witnessed by 16,699.

After 560 regular-season starts and no relief outings, the 39-year-old was facing a new test with his first non-postseason appearance out of the pen. He did work one ALDS game in 2011 against the Tigers in relief.

Sabathia delivered a perfect frame Tuesday, in which he struck out the first and third hitters.

“I thought he threw a lot of good cutters to their righties. Good that he was able to do it, walk in from the bullpen which is unique for him,’’ manager Aaron Boone said of Sabathia, whose next relief outing this coming weekend against the Rangers likely won’t be scripted like Tuesday’s was. “Good first step, hopefully he bounces back well from it [Wednesday] and we will try it again in Arlington.’’

Tom Glavine is the only other pitcher to open a career with more consecutive starts than Sabathia. Glavine’s 682 career reglar-season appearances (and 34 more in the postseason) all came as a starter.

The loss dropped the Yankees a game back of the Astros in the race for home-field advantage, pending the outcome of the Astros’ game Tuesday night at Seattle. Should the Yankees and Astros finish with identical records Houston would claim the home field advantage thanks to winning the season series, 4-3.

Cameron Maybin staked the Yankees to a 1-0 lead in the third inning but Kevin Kiermaier, the Rays’ No. 9 hitter, got that back in the fifth inning with a two-out homer to right off Stephen Tarpley.

Seven innings later, former Yankee Ji-Man Choi opened the 12th inning with a towering homer to right off Cory Gearrin to keep the Rays a half-length ahead of the Indians for the second AL wild-card spot.

After another day of positive injury news on Edwin Encarnacion and Gary Sanchez, the Yankees watched third baseman Gio Urshela leave the game following the top of the seventh after getting hit in the left hand by a Diego Castillo pitch clocked at 96-mph in the sixth. In the 11th inning, it was announced Urshela, who is hitless in 18 at-bats, had a bruised left hand and X-rays were negative.

Chad Green struck out all three Rays in the 10th to extend his consecutive strikeouts streak to seven, then pushed it to nine by whiffing Austin Meadows and Brandon Lowe to start the 11th. Green’s streak ended when Travis d’Arnaud fouled out to first baseman Luke Voit.

The Yankees used 11 pitchers and the Rays, who limited the Yanks to two at-bats with a runner in scoring position from the sixth inning on, used nine hurlers.

Yet the biggest emphasis was on Sabathia — and he didn’t disappoint.

“He threw the ball good, a little extra life,’’ catcher Austin Romine said. “It’s CC. If you talked to him he would expect that. He threw the ball real well, cutters at 88-89 mph. A guy of that caliber, he knows what he is doing.’’

In a brand new world.