“It was one of those moments in the career of a young player when you have to earn some stripes and stay out there,” said veteran outfielder Jonny Gomes. “You can’t win a game sitting on the bench.”

Perseverance paid off for Middlebrooks Thursday night. His three-run double in the ninth inning gave the Sox a 4-3 victory against the Tampa Bay Rays.

The two-out, two-strike hit off closer Fernando Rodney was perhaps the biggest of the season to date for the Sox. After losing three series in a row, they took two of three from the Rays and moved into second place, a game behind the Yankees.

After losing nine of 11, the Sox have won two straight and may be going back in the right direction.

J. Meric/Getty Images

Will Middlebrooks hit a three-run double in the ninth inning gave the Sox a 4-3 victory over the Rays.

“I think it can have a carryover,” manager John Farrell said. “We’ve gone through a pretty tough 10-day stretch. But I think what’s most important the last couple of nights is the approach that we’ve used for the majority of this season. It showed up again tonight, particularly in the ninth inning against Rodney.”

With the Sox down, 3-1, Dustin Pedroia and David Ortiz drew walks. With Pedro Ciriaco running at first base for Ortiz, Mike Napoli struck out. Daniel Nava then walked to load the bases.

Middlebrooks was on deck watching closely when Rodney struck out Stephen Drew with three straight changeups for the second out of the inning. He figured he would get the same.

“I was up there looking changeup,” Middlebrooks said. “It surprised me. In the past when I’ve faced him it’s changeup, changeup, changeup. It’s his best pitch.”

Instead Rodney threw three consecutive fastballs. The first was 97 miles per hour, the second 98, and the third 100. Middlebrooks took a strike on the first, fouled off the second, and took the third for a ball.

Rodney probably should have stayed with his fastball given how unsure Middlebrooks looked against it. But he threw a changeup that stayed up in the strike zone.

“Maybe the only pitch I threw bad,” Rodney said.

Middlebrooks lined it into the gap in left field. Two runs were sure to score and Nava came around from first when the ball got by left fielder Matt Joyce and skidded to the wall on the artificial turf.

On Tuesday, the Red Sox lost a game when Napoli couldn’t find a popup in the Tropicana’s white roof that fell in for a two-run single. This time the stadium aided the Sox.

Middlebrooks is 8 of 27 with eight extra-base hits in seven games since bruising his ribs. A .211 batting average is nothing to get excited about. But it beats the .190 it was.

“I got frustrated a little bit. But I never changed my plan. I never changed routine at the field and my teammates, they had my back the whole time,” Middlebrooks said.

Farrell believes Middlebrooks is more relaxed at the plate since the collision.

“If he chases a pitch, he regroups. He doesn’t expand the [strike] zone consistently,” Farrell said. “When he was going through a little bit of a spell, that was the case.”

Once Middlebrooks got over the initial shock of the injury, he was determined to play.

“I wasn’t going to get any better sitting out,” he said. “You need reps, you need to get out there and fix stuff on your own and not just say, ‘I’m going to go sit down.’ That’s the selfish way to go about it I think. I wanted to do anything I could do to help my team win.”

Junichi Tazawa (3-2) went two innings for the win. He stranded two runners in the ninth by getting James Loney to ground to shortstop.

Red Sox starter Felix Doubront had a wildly inconsistent five innings. On the positive end, he allowed two runs on just three hits and struck out seven. But he also walked a career-high six and threw 105 pitches, 54 for strikes.

“Much improved,” Farrell said. “The work he and Juan [Nieves, the pitching coach] have been doing between outings seemed to pay off. He was on the plate with his stuff, all three pitches. I thought he had better conviction to the stuff that he threw tonight.”

About those walks . . .

“We have to take one step at a time,” Farrell said.

Clayton Mortensen relieved Doubront in the sixth inning and allowed a run. The Sox went into the ninth with three hits, but found a way to beat Rodney (1-2).

The Sox had not won when trailing after eight innings since July 19 when they beat the White Sox, 3-1, on a walk-off home run by Cody Ross.

Pedroia was on base for that, too.

“These kind of wins are big ones,” he said. “It doesn’t matter who it’s against. We had good quality at-bats in a row and Will gets the big hit. It’s uplifting for everybody. We’re all excited.”

BostonGlobe.com complimentary digital access has been provided to you, without a subscription, for free starting today and ending in 14 days. After the free trial period, your free BostonGlobe.com digital access will stop immediately unless you sign up for BostonGlobe.com digital subscription. Current print and digital subscribers are not eligible for the free trial.

Thanks & Welcome to Globe.com

You now have unlimited access for the next two weeks.

BostonGlobe.com complimentary digital access has been provided to you, without a subscription, for free starting today and ending in 14 days. After the free trial period, your free BostonGlobe.com digital access will stop immediately unless you sign up for BostonGlobe.com digital subscription. Current print and digital subscribers are not eligible for the free trial.