Bregman homered twice and his tapper just in front of the plate in the 11th inning led to a bizarre sequence that ended the game, as Lucroy’s throwing error handed the Astros a 6-5 victory over the Athletics.

“It was a crazy play,” said Oakland manager Bob Melvin, who had to watch it from the clubhouse after being ejected for arguing a check swing in the fourth. “Crazy way the game ended.”

Justin Verlander pitched six sharp innings and the Astros took a 4-0 lead into the ninth before the Athletics tied it.

Stephen Piscotty hit a solo homer with two outs in the top of the 11th off Collin McHugh (5-0) to put the A’s ahead, but the Astros staged their own rally.

All-Star closer Blake Treinen (5-2) walked pinch-hitter Josh Reddick, who went to third on a single to right field by rookie Kyle Tucker. With the infield playing in, Tony Kemp hit a grounder to shortstop Marcus Semien. He made a low throw home that Lucroy was unable to handle, allowing Reddick to slide in safely with the tying run.

With one out, Bregman’s dribbler started out foul before spinning into fair territory just a few feet up the first base line. Bregman failed to run initially, so Lucroy scooped up the ball and reached for Bregman as he backpedaled — the bat still in his hand — in an effort to dodge the tag.

But the ball slipped out of Lucroy’s bare hand, pinballed off plate umpire David Rackley and Lucroy, and then fell to the ground.

“That’s when we were playing dodgeball there for a couple of seconds,” Lucroy said. “That was just a big mess, a big zoo behind the plate there. Hopefully I never have to see that again. That’s the first time that’s ever happened in my eight years. Hopefully it’s the last time.”

Still with plenty of time, though, Lucroy picked up the ball, set his feet with an angle to throw to first base — and fired the ball off the back of Bregman’s helmet as he ran up the line.

The ball ricocheted into foul territory in right field, and Tucker trotted home with the winning run.

Following a replay review, the play stood as called on the field.

Bregman was glad things worked out in Houston’s favor, but mad that he swung at what he called a “horrible pitch.”

He called his swing “the biggest circus of the whole thing,” and added: “I think it was the softest ball anyone’s ever hit.”

Treinen had converted 20 straight save chances since April 18.

Houston reliever Ken Giles allowed three consecutive singles with nobody out in the ninth as the A’s pulled to 4-1. The television broadcast appeared to show Giles cursing at manager AJ Hinch as he was lifted. Hinch was asked about the outburst by Giles, who earlier this season punched himself in the face as he left the mound following another bad outing.

“That stuff happens in the heat of battle,” Hinch said. “I’ll have to look at it. He can let me know if it was directed at me; I didn’t hear anything. And you can certainly understand that I’ll address it if it turns out it was at me.”

Giles was replaced by Hector Rondon, who was greeted by an RBI single from Matt Olson to make it 4-2.

Rondon struck out Piscotty before a wild pitch left runners at second and third. There were two outs when Semien’s second double of the game tied it at 4.

Bregman hit his first homer off Sean Manaea in the first inning. George Springer added RBI singles in the second and fourth to make it 3-0.

Bregman, chosen for his first All-Star Game on Sunday, connected off Emilio Pagan in the seventh for the first multihomer game of his career.

Verlander yielded three hits and struck out six, lowering his ERA to an AL-best 2.05. Manaea allowed seven hits and three runs in four-plus innings.

The Athletics hadn’t given up a run in 23 1/3 innings when Bregman homered in the first.

“That was a very rewarding phone call I got to make today, because we all know he should have been on the team,” Melvin said. “And he was having a tough time with it, as well.”

It’s the first career selection for the 11-year veteran.

“Showed some perseverance and worked hard to get to this point so any All-Star Game would have a lot of meaning,” Lowrie said. “But I think for the first time as a 34-year-old, it’s pretty special.”

TRAINER’S ROOM

Athletics: RHP Trevor Cahill (strained right Achilles) is expected back from the disabled list to start Thursday in the series finale.

Astros: SS Marwin Gonzalez left before the second inning after being kicked in the left wrist and elbow by Dustin Fowler when he tagged him out as he tried to steal second base in the first. The team said Gonzalez had a bruised wrist and elbow and is day-to-day.

UP NEXT

Lance McCullers (10-3, 3.41 ERA) will pitch for Houston against Chris Bassitt (1-3, 3.00) when the series continues Wednesday. McCullers struck out a career-high 12 in his last start to extend his winning streak to four games. Bassitt is 1-0 with a 1.69 ERA in two starts since being recalled from Triple-A Nashville on June 27.