BOSTON — Following Josh Hamilton’s resurgence, the Texas Rangers outslugged the Boston Red Sox.

Hamilton continued to work his way back from of a prolonged slump and the Rangers belted four homers to beat the Red Sox 10-9 despite blowing a late four-run lead Wednesday.

Hamilton homered among his three hits and had four RBIs for Texas, which couldn’t hold a 9-5 edge before pulling out its sixth win in eight games.

“He’s the heart of the lineup,” said right fielder Nelson Cruz, who added a two-run homer. “When he’s doing good, everybody’s seeing more pitches to hit and drive runners in.”

Mitch Moreland and Geovany Soto also homered for the Rangers. It was Soto’s first with Texas since being acquired from the Chicago Cubs in a non-waiver deadline deal last week.

It was only Hamilton’s fourth multi-hit game in his last 27. Before Wednesday, he had just two homers and 16 RBIs since the All-Star break.

“I saw him coming out of it a week or so ago,” Rangers manager Ron Washington said. “He’s laying off the real bad pitches. Because Josh is a swinger, he’s going to swing at some pitches. … He’s swinging the bat well. When he’s going real well is when there’s RBIs out there, and he’s not missing very many.”

The AL West-leading Rangers took two of three from Boston, closing their road trip at 4-2.

Will Middlebrooks had a three-run homer for the second straight game, and Cody Ross added a solo shot and drove in two runs for Boston, which has lost six of eight and went 4-6 on its longest homestand of the season.

Adrian Gonzalez added three RBI doubles for the Red Sox.

Alexi Ogando (2-0) worked two perfect innings of relief for the win. Joe Nathan pitched the ninth for his 23rd save, striking out the last two batters with a runner on second.

But with all the power displayed, it took Adrian Beltre’s tiebreaking sacrifice fly in the ninth inning to lift Texas to the win.

With the score tied 9-all, Elvis Andrus walked and moved to third on Hamilton’s single off Clayton Mortensen (1-1). Alfredo Aceves relieved before Beltre’s sacrifice fly.

Josh Beckett gave up a season-high eight runs on eight hits — three homers — in his first start for Boston since leaving July 31 with a back spasm. It’s the seventh time he’s given up eight or more runs at Fenway Park, four times against the Yankees, the last coming May 7, 2010.

Beckett’s career-best streak of starts without surrendering a home run was halted at 12. It was the longest in the majors’ this season and most by a Red Sox starter since Mel Parnell’s 14 straight in 1948.

“The back felt good. Just too many pitches down the middle of the plate and everything was up,” he said. “Even when I was on the corners it was still up.”

Trailing 9-5 in the seventh, Boston tied it when Gonzalez had his third run-scoring double and Middlebrooks homered into the left-field seats off reliever Roy Oswalt.

The Rangers had chased Beckett and built an 8-5 lead in the sixth. Soto homered into the seats above the Green Monster after David Murphy singled. Beckett was booed loudly as he walked slowly off the mound after being pulled.

Cruz’s homer off Mortensen made it 9-5 in the seventh.

Red Sox manager Bobby Valentine felt his lineup showed extra fight despite a poor outing by Beckett.

“I don’t think it’s deflating. I think the offense feels good when they’re scoring runs,” he said. “They think they’re swinging the bats well and that they can come back.”

With the score tied 3-3 in the fifth, Moreland led off with a homer off a TV stanchion in straightaway center. Andrus singled before Hamilton hit a shot deep into the right-field seats for his 30th home run, making it 6-3 and giving the slugger his third season of 30 or more homers.

Gonzalez’s second RBI double had cut the score to 6-4 in the fifth. Texas starter Matt Harrison then loaded the bases with consecutive two-out walks before he was lifted for Oswalt. Gonzalez scored on catcher Soto’s passed ball, slicing it to 6-5, but Kelly Shoppach struck out to end the threat.

Harrison was charged with five runs — four earned — on eight hits in 4 2-3 innings. Washington said he was feeling sick and got an IV during the game.

The Rangers continued Beckett’s season-long first-inning misery, jumping ahead 3-0. Hamilton had a two-run triple into the center-field triangle and scored on Beltre’s sacrifice fly.

Beckett’s ERA rose to 10.42 in the first innings of his starts.

In the first, Gonzalez’s RBI double and Ross’ run-scoring single made it 3-2.

Ross’ homered in the third — his first in 18 games — just inside the left-field foul pole, tying it at 3.

NOTES: It was just Hamilton’s second homer in his last 19 games. … Red Sox DH David Ortiz, on the 15-day DL since July 18 with a strained right Achilles, did some agility drills and looked good running the bases about two hours before the game. On Tuesday, he took batting practice on the field and said he hopes to return when the club plays in Cleveland this weekend. … Boston placed RHP Vicente Padilla on the 15-day DL before the game with right arm tightness and recalled RHP Mortensen from Triple-A Pawtucket. … The Rangers put C Yorvit Torrealba on waivers. If he’s not claimed by Friday he’ll become a free agent. He was designated for assignment when the club acquired Soto from the Cubs on July 31.