BOSTON – The Boston Red Sox waited for Josh Beckett to recover from his sprained right ankle before letting him get back on the mound.

And he returned to the rotation just in time.

In his first start in 11 days, Beckett pitched six solid innings to lead the Red Sox to a 4-3 victory over Tampa Bay on Friday night, slowing the charge of the third-place Rays and extending Boston’s lead in the American League wild-card race to four games. It was the second win in nine games for the Red Sox and their first in seven tries against the Rays.

“We need him to be Beckett. We don’t need him to be Beckett in name only,” Red Sox Manager Terry Francona said. “Despite what’s been happening, we want him to have a chance to pitch effectively. So we weren’t going to pitch him unless he was ready.”

The Rays trailed Boston by nine games on Sept. 3 and had a chance to catch them with a four-game sweep in Fenway. But trade-deadline pickup Mike Aviles broke a fourth-inning tie with his first homer since joining the Red Sox, and Boston assured itself of the wild-card lead at least through the end of the weekend.

“As tough as the last 10 days have been, playing in this atmosphere — this is why they work all winter,” Francona said. “This is exciting. I was as nervous as can be.”

Jonathan Papelbon pitched the ninth for his 30th save — his first since Aug. 18 — striking out Evan Longoria with a runner on second to end the game. But the best news might have been the performance of Daniel Bard, who rebounded after three straight losses to strike out three in a scoreless eighth.

“I don’t know what anybody else is saying, but he’s Daniel Bard. I want him pitching the eighth every game I start for the rest of my career,” Beckett said. “I don’t know if that’s going to happen, but I’d like my chances.”

James Shields (15-11) lost for just the second time since July. Longoria homered for the second straight night and Desmond Jennings had three hits for the Rays.

Boston ace Jon Lester faces Jeff Niemann today.

Beckett (13-5) left his Sept. 5 start with a sprained ankle and skipped his next turn in the rotation. He allowed three runs — two earned — Friday night, giving up seven hits, an intentional walk and a hit batter while striking out seven. He fanned John Jaso with a runner on third to end the sixth, a called strike that got Rays Manager Joe Maddon ejected.

In two previous starts against Tampa Bay this season, Beckett pitched 17 scoreless innings, allowing just a pair of infield singles.

But he ran into trouble early Friday night when Jennings led off the game with a bunt single and took second on Beckett’s throwing error; two batters later, Longoria homered off the top of the Green Monster.

The Red Sox tied it in the bottom half on RBI singles by Dustin Pedroia and David Ortiz. The teams matched runs in the third before Aviles, who was acquired from the Kansas City Royals on July 30, sent one off the billboard behind the Monster seats — his first homer since joining the Red Sox.

“He got a pitch he could reach and he whacked it,” Francona said. “I don’t care who hits them right now. It was nice seeing that ball leave the ballpark.”