BALTIMORE — The Boston Red Sox belted five homers, four of which came in the first three innings, and finished with 15 hits. Still, that was not enough to beat the Orioles on Wednesday night.

Matt Wieters reached on an error that gave the Orioles the lead for good and later added a two-run single as Baltimore scored a 13-9 victory over the Boston Red Sox in a slugfest.

Despite being known for their power, the Orioles (29-22) did not hit a homer. But they finished with 13 runs on 14 hits and went 6-for-18 with runners in scoring positions.

“I like the fact we scored a lot of runs without (homers),” Orioles manager Buck Showalter said. “But obviously we had some trouble getting them out and so did they. Our guys just refused to be outscored tonight.”

Wieters led the way with three RBIs, two of which came on a single in the seventh, which made it 12-8.

“That’s an offense over that’s going to grind out at-bats, and if you make mistakes to that offense, they’re going to put up runs,” Wieters said. “So to be able to answer them is big.”

Hyun Soo Kim and Pedro Alvarez both paced the Orioles with three hits. Manny Machado, Mark Trumbo, Ryan Flaherty and Jonathan Schoop each added two RBIs.

Kim is slowly finding his way in recent days. Showalter’s been giving him more playing time as rookie outfielder Joey Rickard has slumped lately.

Kim now has six multi-hit games this season and hits in 12 of his 19 games — with an average of .382.

“I’m trying my best to make better hits out there,” Kim said through an interpreter. “And definitely by seeing a lot more balls by the pitchers allows me to be a lot more adapted.”

The game dragged on early thanks to all of the homers — it lasted 3 hours, 58 minutes overall — with Mookie Betts hitting two more homers after getting three on Tuesday.

Betts, according to Elias Sports Bureau, became the first player in major league history to hit homers in the first and second inning in back-to-back games with his two round-trippers in this contest.

He also tied a major league record for the most homers in a two-game stretch (five) and became the third member of the Red Sox to do it. Carl Yastrzemski and Nomar Garciaparra were the others, also according to Elias.

“It would have felt a lot better winning the game,” Betts said. “I feel pretty good. Just riding the wave.”

The game swung back and forth early and was tied at seven going into the fourth. Baltimore (29-22) eventually took the lead in the sixth when second baseman Dustin Pedroia made an error on a possible double-play grounder from Wieters off Clay Buchholz (3-6).

The ball squirted through Pedroia’s legs and into right field, letting Chris Davis score and snap an 8-8 tie.

“I missed it,” Pedroia said. “We’re not robots. It’s part of the game. You make errors sometimes.”

Ryan Flaherty made it 10-8 later in the inning on a groundout. Wieters then added his two-run single off Matt Barnes in the seventh which gave the Orioles the 12-8 lead.

Schoop made it 13-8 with his RBI single two batters later.

The Red Sox (32-21) now have nine homers in the last two games and battered Orioles starter Mike Wright for four early homers.

In addition to Betts’ early blasts, Chris Young also hit two homers, a two-run shot in the second and a solo homer in the eighth and drove in three runs overall.

David Ortiz added a solo homer in the third. The Red Sox pounded Wright for six runs on seven hits in just 2 2/3 innings. Xander Bogaerts stretched his hitting streak to 25 games for Boston.

After that, the Baltimore bullpen quieted the Red Sox. Vance Worley gave up two runs in 2 2/3 innings before Brad Brach (5-0) threw 1 2/3 shutout innings. Darren O’Day gave up the Young homer in two-thirds of an inning before Zach Britton registered the final four outs for his 15th save.

Boston starter Joe Kelly ran into just as much trouble as Wright. He allowed seven runs on seven hits in 2 1/3 innings but both starters emerged with a no-decision. The Red Sox sent down Kelly to Triple-A Pawtucket after the game and recalled Noe Ramirez.

Betts gave the Red Sox a 1-0 lead when he homered off Wright on the right-hander’s second pitch of the night.

But the Orioles answered with four runs in the bottom of the first. Trumbo sliced a two-run single to right. Wieters then hit a sacrifice fly, and Alvarez followed with an RBI double.

In the second, Young hit a two-run shot to left, and Betts followed two batters later with his second homer of the game, a solo blast to left that tied the game at 4.

The Orioles made it 5-4 in the second on a Machado sacrifice fly. Ortiz tied the game with a one-out solo homer in the third off Wright.

Worley replaced Wright with two outs and gave up a two-run single to Ryan Hanigan that gave Boston a 7-5 lead in that third inning.

The Orioles then scored eight of the game’s final 10 runs.

“We could not slow them down from the mound,” Boston manager John Farrell said.