ST. PETERSBURG, Fla. — When Kevin Youkilis limped off the field and into the Boston clubhouse Tuesday night, he could have taken David Ortiz with him.

With Ortiz, the Red Sox cleanup hitter, out of the game because of pain in his right ankle, Tampa Bay Manager Joe Maddon decided that under no circumstances would he give Ortiz a chance to beat the Rays.

“That was a fortuitous moment for us,” said Maddon, who ordered Ortiz walked three times intentionally, once putting the potential tying run in scoring position, on the way to a 3-2 victory at Tropicana Field.

“That was very unfortunate for them. But once that occurred, I said: ‘Ortiz is done.’ “

Jeff Niemann (7-2) limited the Red Sox to four hits and an unearned run over six innings, and Tampa Bay’s bullpen shut down Boston for the second straight day.

Niemann walked three and struck out five to win for the first time since a June 8 shutout against Toronto. After winning his first six decisions, he went 0-2 over four starts.

Jason Bartlett drove in Tampa Bay’s first run with a third-inning single off Felix Doubront (1-1), a 22-year-old left-hander filling in for the injured Clay Buchholz. Sean Rodriguez tripled and scored on John Jaso’s grounder, giving the Rays a 2-1 lead in the fifth.

Carl Crawford added a solo homer off Hideki Okajima in the eighth.

Daniel Nava drove in Boston’s first run with a fourth-inning single off Niemann.

Four Rays relievers held the Red Sox to one hit until Bill Hall walked and scored on Eric Patterson’s two-out triple in the ninth off Rafael Soriano.

Soriano, who earned his 23rd save in 24 chances, walked Ortiz intentionally before getting Youkilis’ replacement, Niuman Romero, to ground out to end it.

The Rays also walked Ortiz with two outs in the seventh, moving the possible tying run into scoring position before Romero, who went 0 for 4, grounded out against Lance Cormier.

“It’s part of the game,” said Ortiz, who has been walked intentionally four times in the first two games of this three-game series. “You have to do what you have to do to win.”

The victory was the fourth straight for the Rays, who have won 6 of 7 to move ahead of Boston into second place in the AL East.

“Listen, I don’t take anything for granted, man,” Maddon said of his strategy. “It just falls under the category of it was the right thing to do at that moment. There’s no other way to look at it as far as I was concerned.”

Youkilis was removed in the fourth inning because of pain in his right ankle. X-rays were negative, and he said there’s a chance he may play in today’s series finale.

“I wish I could tell you what happened. Just basically out in the field and felt like I had a cramp in my ankle, which is the most strange thing ever,” Youkilis said. “Somehow I irritated the capsule, so my ankle locked up. I’ll be good to go.”

Youkilis was on his way to the plate to lead off the inning before stepping away from the batter’s box, leaning over and clutching his foot. He sat while a trainer examined him before getting up and limping to the dugout.

Doubront, who beat the Los Angeles Dodgers in his big league debut at Fenway Park on June 18, allowed two runs and five hits over 52/3 innings.