BALTIMORE – For five innings, the Baltimore Orioles couldn’t muster a single hit against Boston right-hander Aaron Cook.

When the Orioles got their third look at the sinkerballer, things changed in a hurry.

Baltimore sent 10 batters to the plate during a five-run sixth and beat the Red Sox 5-3 Wednesday night to move a game ahead of Tampa Bay for the top AL wild-card spot.

The Orioles trailed 2-0 before rallying against Cook, who fueled the uprising with a throwing error on a potential inning-ending, double-play comebacker. The miscue led to three unearned runs and saddled Cook (3-6) with his fourth loss in five starts.

“When you get the ground ball you have to cash in there,” said Boston Manager Bobby Valentine, who was ejected in the eighth. “We’re in the dugout if he makes the play.”

Cook allowed only a pair of walks through the first five innings and got 13 of 15 outs on grounders. The first out in the sixth also came on a groundball, and then the trouble began.

“He started to get it up,” Baltimore’s Adam Jones said. “You start to see somebody three times, you get him.”

Nick Markakis walked and J.J. Hardy lined a single to left. Nate McLouth hit an RBI single, and with runners on the corners Jones hit a bouncer to Cook, who threw wildly to second as Hardy scored the tying run.

“It’s a play I’ve made a 100 times,” Cook said. “I just didn’t get my feet set. We lost because I made an error.”

Matt Wieters put the Orioles in front and chased Cook with an opposite-field, ground-rule double to left. Andrew Miller got Chris Davis to hit a grounder to drawn-in second baseman Dustin Pedroia, who threw home. Jones lowered his left shoulder and ran hard into catcher Jarrod Saltalamacchia, who applied the tag for the second out.

“It was fun. It was awesome,” Jones said of the collision. “It was much needed.

Mark Reynolds followed with a two-run double off Junichi Tazawa for a 5-2 lead, and that was enough to propel the Orioles (64-53) to their ninth win in 11 games.

“I feel like we just don’t give up,” Hardy said.

“We know that at any point we can go out there and score runs.”

Baltimore is alone in second place in the AL East and making a run at the postseason, but manager Buck Showalter says it’s too early to get excited.

“There’s so much baseball to be played and so many (teams) involved in this that I think it’s counterproductive to dwell on it because things can change so quickly in a week’s time,” he said.

Rookie Miguel Gonzalez (5-2) allowed two runs and six hits in six innings for the Orioles and Jim Johnson worked the ninth for his 35th save in 38 tries.

The game ended with rookie third baseman Manny Machado making a diving stab of Nick Punto’s liner down the line.

Carl Crawford had two RBI for the Red Sox, who have lost six of eight to fall four games under .500 (57-61) for the first time since May 13.

Cleanup hitter Adrian Gonzalez and Valentine were both ejected in the eighth inning for arguing with home plate umpire Mike Everitt.

Both contended that Orioles reliever Pedro Strop threw a quick pitch to Gonzalez, who bounced out to second.

“I wasn’t even set,” Gonzalez said.

“I was just sitting there waiting for him to come set so I can get into my stance. We’re trying to win a game. I’m the leadoff hitter, down two runs, trying to get on base.”

Crawford got Boston to 5-3 in the seventh with a run-scoring groundout, but Boston went down in order in the eighth and ninth.

The Red Sox are 3-8 against Baltimore this season and have lost five of the past six series between the teams dating to last season.