ST. PETERSBURG, Fla. — The Baltimore Orioles are heading to Detroit for an important series after a tough one-run loss to the last place Tampa Bay Rays.

Corey Dickerson had a go-ahead RBI double in the seventh inning to help the Rays beat Baltimore 7-6 on Wednesday and deny the Orioles a three-game sweep.

Baltimore is one game ahead of Detroit for the second AL wild card and started the day one game back of AL East co-leaders Boston and Toronto.

The Orioles and Tigers begin a three-game series Friday night.

“Now we go into another hostile place, and I tell our guys to stay focused on how much fun it is to be playing in these type of games,” Orioles manager Buck Showalter said. “Our guys aren’t dreading it at all. They’re looking forward to being in that arena and being on that stage because they’ve earned the right to be there.”

Dickerson, in a 2 for 28 slide, tied the score 6-all with an RBI single in the fifth and got the decisive hit during the seventh off Mychal Givens (8-2).

J.J. Hardy drove in two on a second-inning double and Michael Bourn hit a solo homer during a three-run third that put Baltimore ahead 5-3.

“I was able to catch one today but especially in a pennant race I rather win,” Bourn said. “It’s hard to sweep a team. As many series as I’ve played, I think about how many sweeps I’ve had and it’s not a whole, whole bunch.”

Baltimore’s Dylan Bundy and Tampa Bay’s Drew Smyly each allowed five runs and seven hits in 3 2/3 innings.

Kevin Kiermaier and Nick Franklin homered for the Rays. Brad Boxberger (3-0) pitched a scoreless seventh for the win and Alex Colome got three outs for his 31st save in 33 chances.

Kiermaier hit a solo shot in the first and then pulled the Rays even at 5 with a two-run single in fourth. He has a career-best 11-game hitting streak.

“He sets the tone quite a bit,” Rays manager Kevin Cash said.

Franklin had a two-run homer in the second.

“You score six runs, you’d like to have a little better result,” Showalter said.

TRAINER’S ROOM

Orioles: 1B Chris Davis (sore left hand) got the day off. … RHP Chris Tillman (right shoulder) is expected to start Sunday against Detroit. … RHP Darren O’Day (right shoulder) could pitch a simulated game Monday or Tuesday.

Rays: RHP Chase Whitley (Tommy John surgery) threw off a bullpen mound, which lines him up to make his first appearance this weekend.

COACHING CORNER

Orioles: Pitching coach Dave Wallace has returned home and will return for Monday.

Rays: New hitting coach Chad Mottola will join the team in New York for Thursday night’s game at Yankee Stadium. Derek Shelton was fired Tuesday.

UP NEXT

Orioles: RHP Kevin Gausman (7-10) faces Tigers RHP Michael Fulmer (10-6) Friday night.

Rays: RHP Alex Cobb (0-0) makes his second start Thursday since returning from Tommy John surgery, facing the Yankees and LHP CC Sabathia (8-12). “They’re still in,” Cobb said. “We’ve got a lot riding on this last month, seeing what we have going into next year.”