BALTIMORE — A poor start by Yovani Gallardo and an abundance of missed scoring opportunities cost the Baltimore Orioles a chance to enhance their position in the playoff picture.

Evan Longoria homered and drove in five runs, and the last-place Tampa Bay Rays again played the spoiler’s role in a 7-6 victory over the Orioles on Thursday night.

Baltimore dropped two games behind AL East-leading Boston and dripped into a tie with Toronto for the two AL wild cards after the Blue Jays beat the Los Angeles Angels later Thursday.

Gallardo (5-8) gave up six runs and seven hits in 3 1/3 innings.

When Orioles manager Buck Showalter emerged from the dugout to pull Gallardo in the fourth, many of the hometown fans cheered. They subsequently booed the right-hander as he walked toward the dugout.

In spite of this, Baltimore had runners on the corners with one out in the ninth inning before Alex Colome struck out major league home run leader Mark Trumbo and slugger Chris Davis to earn his 33rd save.

“It’s a tough loss because we fought back and had a chance there at the end,” catcher Matt Wieters said.

Baltimore went 3 for 15 with runners in scoring position.

Tampa Bay has won three straight, including the last two of a three-game series in Toronto. The Rays also defeated the wild-card contending Yankees on Sunday.

“It’s fun that we are playing competitive baseball,” Longoria said. “It’s one thing to go out in a great environment against a team that is a playoff contender, but to be in the game and winning games is the best thing about it.”

Longoria hit his career high-tying 33rd homer with two on in the first inning and added a two-run single in the fourth to increase his team-high RBI total to 91.

Coming off a 6-3 road trip culminated with two successive wins in Boston, the Orioles fell flat against a team they dominated for much of the season. Baltimore is now 11-5 against Tampa Bay, 6-1 at home.

“First game back home, you obviously want to get home and start off on a good note,” Gallardo said. “I’ve been feeling good my past few starts, and I was just a little off.”

Although the temperature was a comfortable 72 degrees and the Orioles are in the midst of a playoff push, the game attracted an announced crowd of only 19,233.

Longoria put the Rays up 3-0 before Gallardo got an out. In 21 starts this season, he’s surrendered 21 earned runs in the first inning.

Baltimore answered in the bottom half with a two-run single by Wieters and a two-run double by J.J. Hardy.

Tampa Bay pulled even in the second, went ahead in the third and used Longoria’s two-run single to make it 7-4 in the fourth.

Baltimore’s Nolan Reimold hit into a double play with runners on the corners in the fourth. The Rays worked out of an even bigger jam in the fifth, retiring Manny Machado, Trumbo and Davis with runners at second and third.

Brad Boxberger (4-1) got the last two outs in the fifth.

Run-scoring groundouts by Hardy and Michael Bourn made it 7-6 in the eighth.

Tampa Bay was eliminated from playoff contention when Toronto beat the Angels.

TRAINER’S ROOM

Rays: 1B Nick Franklin left in the fifth inning with a left hamstring strain. He’s day to day, manager Kevin Cash said. … 1B Logan Morrison will get a second opinion on whether surgery is required for his season-ending left wrist injury. Morrison was injured while taking a swing Sunday and received an MRI this week.

Orioles: OF Steve Pearce will be sidelined until the final week of the season, maybe longer, after receiving a platelet-rich plasma injection in his throwing arm Wednesday. … RHP Darren O’Day (rotator cuff strain) will throw a simulated game Friday.

UP NEXT

Rays: Chris Archer (8-18, 4.05 ERA) starts Friday night, seeking to pad his AL-leading strikeout total of 217. He also hopes to avoid setting the franchise record for losses in a season. The right-hander is currently tied with Tanyon Sturtze, who lost 18 in 2002.

Orioles: RHP Ubaldo Jimenez (7-11, 5.98) strives to win his fourth straight start. He’s got a 2.83 ERA in his last four outings.