Robert Lewandowski saved his team from a humiliating German Cup exit as Bayern Munich came from behind to beat second-tier Heidenheim in a 5-4 thriller on Wednesday.
Bayern was 2-1 down at half-time having gone down to ten men early in the game and threw away a two-goal lead in the second half.
Yet Lewandowski’s late winner ended a rollercoaster resistance from Heidenheim and sent Bayern into the semi-finals.
“I don’t really know what to think of this game,” said Bayern striker Thomas Mueller on Sky Sports.
“After such a great start, it should have gone differently for us. We didn’t play well, particularly after the red card, and it doesn’t feel all that good.”
Everything seemed to be going according to the script when Leon Goretzka headed Bayern in front from a corner on 12 minutes.
Yet the script went up in flames when Bayern went down to ten men just minutes later.
Niklas Suele was initially booked for a challenge on Robert Andrich, but a video review convinced the referee that Suele had denied Andrich a goalscoring opportunity.
The red card galvanised Heidenheim and they forced several chances before Robert Glatzel headed in the equaliser just before the half-hour mark.
Ten minutes later, the Allianz Arena was silenced as Marc Schnatterer fired Heidenheim in front.
Mueller brought Bayern level after half-time, turning in Lewandowski’s header with a marvellous, swivelling finish.
He then returned the favour three minutes later, setting up Lewandowski to restore the lead for Bayern.
Serge Gnabry added a fourth for Bayern on 65 minutes, slotting the ball in at the far post at a corner.
Yet Glatzel stunned Bayern again when he scored twice in three minutes to make it 4-4.
Having pulled a goal back on 74 minutes, the Heidenheim striker completed his hat-trick from the penalty spot.
It ended in disappointment for Heidenheim, however, as a handball at the other end allowed Lewandowski to score the winner with an 84th-minute penalty.
Werder Bremen also reached the semi-finals after they eased to a 2-0 win over Schalke thanks to goals from Milot Rashica and Davy Klaassen.
Rashica’s dipping shot from outside the area broke the deadlock just after the hour mark. Klaassen slotted in a second shortly afterwards to ensure Werder’s place in the last four alongside Bayern, RB Leipzig and old rivals Hamburg.
“We didn’t play very well today but we had the quality to win anyway and we are very happy to be in the semis,” Bremen captain Max Kruse told Sky.
The semi-final draw will take place on Sunday.