BOSTON — Travis Shaw’s teammates teased him about going for the cycle in his last at-bat. He finished with an even better hit by belting his second homer of the day.

Shaw hit his first two major league homers, and went 4 for 4 with five runs scored and four RBI to lead the Boston Red Sox past the Tampa Bay Rays 11-7 on Saturday.

“It’s in your head,” he said. “Everybody’s talking about it. If you hit the ball in the gap everybody’s like: ‘don’t stop running.’ I’ll take the homer.”

Shaw had a double in his first at-bat, homered in the second and singled in the third on a day he didn’t even know if he’d be in the lineup. He was in for third baseman Pablo Sandoval, who was sidelined with a bruised left forearm after getting hit by a pitch Thursday.

“He got the word yesterday,” Red Sox Manager John Farrell said of Shaw being recalled. “He was unsure if he’d play third base until this morning.”

Xander Bogaerts had four hits and three RBI, and Rusney Castillo added three hits with three RBI for the Red Sox, who won a third straight after losing 12 of 14.

Logan Forsythe hit a solo homer and two-run single for the Rays, who have lost 5 of 7.

Joe Kelly (3-6), demoted to the minors in late June for nearly a month, gave up five runs on nine hits in five-plus innings for his first victory since June 6.

“Good thing I had a lot of offense today and the team picked me up,” Kelly said.

Jean Machi earned a save in his Red Sox debut, getting the final four outs.

After having their six-run lead sliced to one, the Red Sox scored two runs on one hit in the sixth against reliever Steve Geltz. Castillo had a two-run single that made it 9-6, with Shaw making a nice slide by tapping the plate with his hand despite the throw beating him.

The Red Sox built a 6-0 edge after three innings against starter Matt Moore (1-3).

Leading 1-0 in the second, they scored four on Castillo’s RBI double, Brock Holt’s sacrifice fly and Bogaerts’ two-run double.

Shaw homered over the Rays’ bullpen, making it 6-0 in the third. His second – a two-run shot – went into the center-field bleachers in the eighth.

Moore, making his sixth start since returning from Tommy John surgery in April 2014, gave up six runs in three innings. He’s failed to go past five innings since his return.

“It’s not fun right now, but I still believe in myself,” Moore said. “I feel like when I was out there competing that I wasn’t being timid.”

The Rays crept back with two runs in both the fourth and fifth, but their bullpen couldn’t hold down the Red Sox.

“We do such a good job of being efficient,” Rays Manager Kevin Cash said. “We weren’t today.”

Bogaerts’ RBI single made it 7-4.

The Rays then cut it to 7-6 on Kevin Kiermaier’s RBI single and pinch-hitter Brandon Guyer’s run-scoring double. Guyer’s hit would have tied it but Kiermaier was caught trying to steal third.

Forsythe’s single came in the fourth. Evan Longoria and James Loney each had RBI singles.

NOTES: Sandoval missed his second straight game for Boston. … Farrell called Travis Shaw the first name of the rookie’s dad, whom Farrell played with. “Jeff Shaw, excuse me, Travis, looks like he’s been here for years the way he swung the bat today,” Farrell said. Later the manager said, “makes you feel old when one of your teammate’s kids are playing for you.”