BOSTON — Erasmo Ramirez pitched seven solid innings, and Evan Longoria’s solo home run sparked a three-run sixth to lift the Tampa Bay Rays to a 4-2 victory over the Boston Red Sox on Thursday night.

Longoria’s homer was his 20th, giving him seven seasons with at least that many. He also had a double and single.

Kevin Kiermaier also hit a solo homer for the Rays, who have won five of their last seven games.

Boston’s David Ortiz hit his 36th homer – a two-run shot – and increased his RBI total to 101, reaching the century mark for the ninth season with the Red Sox to tie Hall of Famer Ted Williams for most in club history.

Last place Boston lost three of four to the Rays, falling 2 1/2 games behind them for fourth in the AL East.

Big Papi also set a club record for most seasons with 35 or more homers and 100 RBI with his sixth. Manny Ramirez and Jimmie Foxx each had five.

Erasmo Ramirez (11-6) gave up two runs on four hits, striking out six without walking a batter. Brad Boxberger worked the ninth for his 38th save.

Trailing 2-0, Tampa Bay rallied against Wade Miley (11-11). Longoria homered deep to left-center over the Green Monster. Asdrubal Cabrera and Steven Souza Jr. had consecutive RBI doubles.

Kiermaier homered into the right-field seats leading off the seventh.

Miley allowed four runs on eight hits in 6 1/3 innings.

Boston moved ahead 2-0 in the first when Ortiz homered into the first row of Monster seats.

NOTES: Red Sox interim manager Torey Lovullo said third baseman Pablo Sandoval has pneumonia. He will be re-evaluated Saturday. Originally, the club said he had an upper respiratory infection. … Hanley Ramirez was shut down for the rest of the season because of right shoulder inflammation.