ST. PETERSBURG, Fla. — The Tampa Bay Rays needed something, anything, to break what they felt was a spell of bad things happening to a good team during a losing streak that spanned seven games and eight days.

The All-American Rejects and Fall Out Boy tunes that reliever Pete Fairbanks said some of the players cranked in the clubhouse Wednesday afternoon weren’t necessarily going to be enough.

But they played some bigger hits later, ending their longest losing streak in more than three years with an 8-2 win over the Red Sox before a Tropicana Field crowd of 9,088.

Early two-run homers by Austin Meadows and Mike Zunino, and a three-run insurance shot late from Brandon Lowe, combined with a solid start from Rich Hill and the usual sturdy relief work, were keys to the win.

The Rays improved to 44-31 and moved back within a half game of the American League East-leading Sox.

The Red Sox scored a run off Hill in an odd first, with Xander Bogaerts singling in Alex Verdugo. But before the Rays could think things were going badly again, they struck for two runs off Garrett Richards in the first.

Wander Franco, in his second big league game, drew a two-out walk. Three pitches and two pickoff attempts later, Meadows laced a two-run homer to right-center field, his team-leading 16th.

Then the Rays made things better, as they scored three in the second. Brett Phillips drew a one-out walk and Zunino followed with another two-run homer, his 15th. Lowe doubled, and Franco bounced a ball that second baseman Kike Hernandez fielded but then threw errantly, allowing Lowe to score.

The Rays made it 8-1 in the seventh as Joey Wendle was hit by a pitch, Manuel Margot singled and with two outs Lowe went deep, hitting his fifth homer in his last 16 games, and his 16th overall.