"I’d love to keep going," Longoria said. "We’ve got plenty of games left, and I’m seeing the ball pretty well right now. Just trying to stay where I’m at mentally and physically."
Baltimore ace Chris Tillman (16-6) had a one-hitter and a 2-1 lead after five innings, but he failed to get out of the sixth.
Longoria led off the inning by hitting a long fly ball outside the left-field foul pole. He sent the next pitch over the center-field wall — his eighth career homer off Tillman in 63 at-bats.
"It was pretty impressive," Rays manager Kevin Cash said. "You don’t see many guys go homer foul and then straighten it out a little more."
Brad Miller followed with an infield hit and scored on a two-out double by Richie Shaffer.
The Rays added two unearned runs in the eighth when Mikie Mahtook hit a bases-loaded single after an error by first baseman Chris Davis.
Tampa Bay has won two of three in the series that ends Sunday.
"You say what you want about the Rays and the standings, but they’ve got a formidable major league team over there," Orioles center fielder Adam Jones said. "They’re not just laying down, dying, quitting and just letting us win."
Matt Andriese (8-7) allowed two runs in 5 1/3 innings to win his second straight start after losing seven decisions in a row.
"He had nasty stuff going. You could tell from the side, a lot of stuff was bottoming out," Cash said. "The slider and the changeup kept those guys off balance."
Alex Colome worked the ninth for his 34th save in 36 chances.
The Orioles played a second straight game without major league home run leader Mark Trumbo, who has back spasms.
Baltimore got a first-inning run when Jones doubled and scored on a fly ball by Manny Machado.
A sacrifice fly by Hyun Soo Kim made it 2-0 in the third. Tampa Bay broke through in the fourth when Longoria tripled — the Rays’ first hit — and scored on a grounder by Miller.
Rays: 1B Nick Franklin missed a second straight game with a hamstring strain and will likely be re-examined Monday after the team travels home.
Orioles: Trumbo could return Sunday. "He’s better, improved, close," manager Buck Showalter said. RHP Darren O’Day (rotator cuff strain) should come off the disabled list on Sunday or Monday, Showalter said.
Rays: Jake Odorizzi (9-6, 3.81 ERA) pitches the series finale for the Rays. He’s 6-1 since the All-Star break and has 15 starts overall in which he received no decision.
Orioles: Wade Miley (8-13, 5.80) starts for Baltimore. He’s 1-5 with an 8.41 ERA in eight starts since coming to the Orioles just before the non-waiver trade deadline.