Gladbach's dream start yielded two goals for Ramy Bensebaini and one from Kouadio Kone to put them in the driving seat before Breel Embolo struck twice early in the second half to kill off the game.
They became the first team to score five goals against the mighty Bavarians since Borussia Dortmund's 5-2 win in the 2012 German Cup final, and the first-ever team to score three goals in the first 21 minutes against Bayern in a German Cup game.
They needed just 80 seconds to open their account with Kone pouncing on a sloppy pass by Bayern's Alphonso Davies to beat keeper Manuel Neuer.
With the Bayern defence in complete disarray, the hosts should have scored again with Jonas Hofmann and Embolo coming close as the defensive efforts by the visitors piled up.
Gladbach did it better in the 15th, outplaying the static Bayern backline for Bensebaini to thunder a Hofmann cutback past Neuer.
Gladbach defeat Bayern Munich 5-0
Before they had any time to recover Lucas Hernandez, who earlier on Wednesday had seen a six-month prison sentence suspended in Spain, clumsily brought down Embolo in the box and Bensebaini sent Neuer the wrong way with an audacious spot-kick to make it 3-0.
With Bayern coach Julian Nagelsmann confined to his home after testing positive for COVID-19, assistant coach Dino Topmoeller had to wait until the second half to see some decent attacks from his players, who have netted a record 33 times in their first nine league games.
But before they even got into any rhythm, Gladbach struck again with Embolo beating two defenders, who let a high ball bounce between them, to slot the ball in through the legs of Neuer.
The Swiss bagged his second goal of the evening in the 57th, finding far too much space once more to score their fifth off the post.
Borussia Moenchengladbach's stunning 5-0 victory over Bayern Munich in the German Cup second round on Wednesday was like playing in a trance, midfielder Jonas Hofmann said following their first-ever win over them in the competition.
The Foals struck three times in the opening 21 minutes and added two more early in the second half to subject Bayern to their heaviest ever German Cup defeat.
"We had a super start to the game and we were up 3-0 after just over 20 minutes," Germany international Hofmann said. "You have to earn it but everything fell into place tonight.
"It was like in a trance but also exactly what we had set out to do. We defended superbly. It was very good."
The hosts never gave Bayern a chance, going in front after only 80 seconds.
The Bavarian defence looked completely disoriented and a string of errors led to two more goals by the 21st minute. Gladbach could have added several more in an electric first half.
"If you are 3-0 behind after 20 minutes or so then it affects you mentally," Hofmann said. "Then even Bayern players are only human. We can pat ourselves on the back. You cannot hope for a better start than that against Bayern."
The visitors never managed to get back into the game and when man-of-the-match Breel Embolo scored twice in six minutes early in the second half, it was lights out for Bayern.
"You dream sometimes of something like that," Gladbach sports director Max Eberl said. "But you do not ever think that it could actually become reality.
"It is a historic performance. This evening will go into Gladbach's history books."
At the end of the game, the Bavarians were left trying to figure out what exactly had happened, given their dominant domestic and international performance so far this season.
Sports director Hasan Salihamidzic said the absence of coach Julian Nagelsmann, who was at home following a positive test for Covid-19, played no part in the loss as they had easily won their previous two matches without him.
"We knew it would be tough here in Gladbach," Salihamidzic said. "But we did not expect such an evening. It is really difficult to explain what happened, to be honest. A collective blackout."