BALTIMORE — Orioles Manager Buck Showalter had already seen plenty of wacky things happen during a wild, back-and-forth slugfest.

Then, things got really weird.

A potential double-play grounder whisked through the legs of Boston second baseman Dustin Pedroia, and Baltimore turned the miscue into the tie-breaking run in a 13-9 victory over the Red Sox on Wednesday night.

Matt Wieters had three RBI for the Orioles, who won for the third time in 10 games despite allowing five home runs – another two by Mookie Betts. Baltimore, by contrast, failed to go deep yet still reached a season high in runs.

Pedroia’s error came in the sixth inning with the score tied at 8. After Clay Buchholz (3-6) walked Chris Davis and Mark Trumbo, Wieters hit a grounder to second. The ball skidded under Pedroia’s glove, and Davis scored to give Baltimore the lead for good.

“That’s when you know it’s Twilight Zone night,” Showalter said. “Actually, when it happened I said, ‘We might have a shot.’ He’s one of the best second basemen you’ll ever see.”

Pedroia – a four-time Gold Glove winner – had two errors in 50 games this season.

“I missed it. We’re not robots,” Pedroia said. “It’s part of the game, man. You make errors sometimes. Just wish they are not in that situation, but it’s part of it.”

The Orioles added another run in that inning and pulled away with a three-run seventh.

Hyun Soo Kim and Pedro Alvarez each had three hits, and Davis drew four walks for Baltimore.

Xander Bogaerts extended his hitting streak to 25 games – second-longest in the majors this season – and Betts added two homers to go with the three he clocked on Tuesday night. After connecting in the first and second innings of this game, Boston’s leadoff hitter had five home runs in seven at-bats.

“I feel pretty good,” he said. “Managing my at-bats well. Just riding the wave.”

Chris Young also homered twice for the Red Sox, and David Ortiz had a solo shot to move into a tie with Jim Rice for third place on the team’s RBI list with 1,451.

After the game, Boston optioned starter Joe Kelly to Triple-A Pawtucket and recalled right-hander Noe Ramirez from the same minor league club. Kelly allowed seven runs in 21/3 innings and ended the night with an 8.46 ERA.

Brad Brach (5-0) pitched 12/3 innings of scoreless relief for Baltimore, which pulled within two games of first-place Boston in the AL East.

Zach Britton got four outs for his 15th save.

The first three innings featured 15 runs, 17 hits and two starting pitchers fortunate to emerge from the mess with a no-decision.

Baltimore offset Betts’ second leadoff homer in two games with a four-run first against Kelly, who quickly realized that earning his 11th straight win was not going to be easy.

Home runs by Young and Betts tied it in the top of the second. The Orioles went up 5-4 in the bottom half, and each team scored three runs in the third.

Baltimore starter Mike Wright yielded a career-high four home runs before being pulled with two outs in the third.

NOTES: Betts joins about two dozen players in major league history to hit five home runs in two consecutive games. The last player to accomplish the feat was Bryce Harper in a doubleheader on May 6, 2015. The only other Red Sox players to do so were Carl Yastrzemski on May 19-20, 1976, and Nomar Garciaparra on July 21 and 23, 2002. Betts also became the first Red Sox hitter to hit home runs to lead off consecutive games since Mike Aviles on May 19-20, 2012. … OF Brock Holt (concussion) took batting practice for the first time since his injury May 19 and also participated in fielding drills for a second day. He will need a minor league rehabilitation assignment before returning, Manager John Farrell said.