Bayern Munich scraped into the German Cup semi-finals by beating second-tier Heidenheim in a nine-goal thriller.
Heidenheim had led 2-1 with goals from Paul Glatzel and Marc Schnatterer after Leon Goretzka opened for Bayern, who had Niklas Sule sent off.
Thomas Muller, Robert Lewandowski and Serge Gnabry put Bayern 4-2 up, only for Glatzel to score again and then convert a penalty for his hat-trick.
Bayern avoided extra-time through Lewandowski's late penalty.
The German champions, runners-up in last year's competition, have now reached the semi-finals for 10 consecutive years but were perilously close to going out to a lower-division side for the first time in 15 years.
South German club Heidenheim, sixth in the second division, were a fourth-tier side as recently as four years ago.
Bayern, second in the Bundesliga, face a crucial match against leaders Borussia Dortmund, who are two points ahead, on Saturday.