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 fell even with Toronto in the loss column in the race for the top wild-card spot, pending the Blue Jays’ late game against the Angels.

Gallardo (5-8) gave up six runs and seven hits in 31/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 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.

TWINS 5, TIGERS 1: Brian Dozier’s two-run single highlighted a four-run second inning and Minnesota handed host Detroit a crucial loss.

The Tigers were only able to split four games with the lowly Twins, hurting them in the crowded AL wild-card race. Detroit came into the series with a 10-2 record against Minnesota.

WHITE SOX 2, INDIANS 1: Jose Abreu continued his torrid streak with a home run and a single, and Carlos Sanchez drove in the winning run in the ninth as Chicago won at home.

The White Sox took three of the four games in the series to conclude a 6-4 homestead against three playoff hopefuls.

David Robertson (5-3) pitched a scoreless inning to earn the victory.

ATHLETICS 14, ROYALS 5: Stephen Vogt drove in five runs, Ryon Healy hit a mammoth three-run homer and Oakland routed the Royals at Kansas City, Missouri.

The A’s continued to wreak havoc on the Royals’ diminishing playoff chances, sweeping a four-game road series at Kansas City for the first time in their history. The A’s outscored the Royals 43-12, the largest Oakland run differential in a four-game series in franchise history.

NATIONAL LEAGUE

BREWERS 5, CUBS 4: Scooter Gennett hit a tie-breaking, two-run double in the seventh inning, and visiting Milwaukee spoiled Chicago’s first opportunity to clinch the NL Central title.

Chicago (93-53) was hoping to begin a 10-game homestand with a boozy celebration of its first division title since 2008. But Keon Broxton homered and Orlando Arcia drove in two runs for Milwaukee, making the Cubs wait for the result of St. Louis’ game at San Francisco to find out if their season-long dominance of the Central was complete.

PIRATES 15, PHILLIES 2: Andrew McCutchen hit two solo homers, Chad Kuhl pitched six effective innings and Pittsburgh won at Philadelphia.

Jordy Mercer hit a three-run homer, and John Jaso and Sean Rodriguez also went deep to help the Pirates split a four-game series.