ST. PETERSBURG, Fla. -- The Tampa Bay Devil Rays could only keep David Ortiz's bat quiet for so long.
Finally breaking through against the various defensive alignments used to slow him down for three days, the Boston slugger hit his 28th and 29th home runs to help the Red Sox avoid a four-game sweep by Tampa Bay with a 12-5 victory Thursday night.
Ortiz hit a two-run homer in the fifth inning and a grand slam in the ninth. He went 2-for-10 with a solo homer and six strikeouts in the first three games, when Tampa Bay played as many as five players in the outfield when he came to the plate.
"Pretty much what they're trying to do is get in my head," Ortiz said. "I've got to stay with the same approach."
The best way to beat such radical tactics, he said, is to hit the ball out of the park.
"I just figured that hitting the ball up there, no way they can catch it," Ortiz said. "They've really been playing some extreme defense, so I've got to stay where the ball is and try to hit it as hard as I can."
Ortiz, who is tied for AL lead in homers with Chicago's Jim Thome, drove in six runs and has six homers in his last six games. The grand slam off Shawn Camp was his second of the season and sixth of his career. It was his first anywhere except Fenway Park.
Manny Ramirez and Doug Mirabelli also went deep for the Red Sox, who led 6-5 before loading the bases with no outs in the ninth on two singles and a walk. Ortiz drilled the first pitch over the wall in left-center for a career-best 82 RBI before the All-Star break.
"I really thought we were going to be able to come back. ... It's just that inning got out of control," Tampa Bay manager Joe Maddon said. "When you get the bases loaded with that guy in the ninth inning with nobody out, that's a hard spot. And once again, he did not let them down."
Tim Wakefield (7-8), pitching with a sore back, allowed four runs and four hits in five-plus innings to improve to 15-2 lifetime against the Devil Rays, including 7-0 at Tropicana Field. The knuckleballer yielded home runs to Aubrey Huff, Carl Crawford and Jorge Cantu before turning over a two-run lead to the bullpen in the sixth.
Huff's RBI single trimmed Boston's lead to 6-5 in the seventh. Mike Timlin pitched a perfect eighth and Jonathan Papelbon finished up for the Red Sox, who also scored in the ninth on Mirabelli's RBI grounder and an RBI double by Alex Gonzalez.
Ortiz, Ramirez and Mirabelli homered off Tampa Bay starter James Shields (4-2), helping the Red Sox build a 5-2 lead. Mirabelli singled and scored when Gonzalez tripled off reliever Edwin Jackson to make it 6-2 in the sixth.
After falling behind early and losing each of the first three games of the series, the Red Sox got off to a quick start against Shields.
Kevin Youkilis was hit by a pitch to begin the game and Ramirez hit his 24th homer with two outs for a 2-0 lead. It was the All-Star's 223rd home run as a member of the Red Sox -- tied with Hall of Famer Bobby Doerr for sixth on the club's all-time list.
Huff cut into Tampa Bay's deficit with his seventh homer, leading off the fourth. He is 6-for-45 lifetime against Wakefield, however three of his hits off the right-hander have been home runs.
Mirabelli led off the fifth with a homer, and Ortiz's two-run, opposite-field shot to left made it 5-1.
It was the second time in the series, and 39th time overall, that Ortiz and Ramirez homered in the same game.
The Devil Rays chased Wakefield in the sixth when Huff doubled and Cantu followed with his fifth homer, trimming Boston's lead to 6-4.
Shields, who lost his second straight decision after beginning his career with four wins, allowed four hits -- three homers. He walked three and struck out five in five innings.
Despite the loss, the series was a successful start to a difficult seven-game homestand for the Devil Rays, who play three against the Yankees this weekend.
"I'm not upset about a thing right now," Maddon said. "If you said before this series: `How about three out of four?' I think I would have been pretty pleased with that. We're OK."
Boston manager Terry Francona hopes Wakefield's sore back won't keep him from making his next scheduled start. ... Ortiz leads the AL in RBI. His previous best before the All-Star break was 78. ... Ramirez has 38 career homers against the Devil Rays, more than any opposing player. He's hit 23 at Tropicana Field. ... Devil Rays closer Tyler Walker had Tommy John surgery on his right arm by Dr. James Andrews in Birmingham, Ala. His expected recovery time is 12 months.