Bastian Schweinsteiger put Pep Guardiola's men in front but the hosts came back to secure a win which could keep them in the Bundesliga
Nils Petersen - who spent two years with Bayern earlier in his career - was introduced as an 87th-minute replacement for fellow goalscorer Admir Mehmedi.
And with almost his first touch he turned home from a precise cross to give the struggling hosts victory at the Schwarzwald Stadion, which boosted their survival hopes and sent Bayern to a third straight league defeat.
Bastian Schweinsteiger had earlier scored on his 500th competitive appearance for Bayern, but his first-half strike was a rare bright spot for Pep Guardiola's embattled side.
Freiburg drew level through Mehmedi's equaliser 12 minutes before the break and, in the end, they were value for their late winner.
Bayern showed signs of tiredness following their midweek Champions League exit at the hands of Barcelona, and the result will do little to ease the negative press Guardiola has faced - despite having wrapped the title up with room to spare again this term.
Guardiola showed faith in the under-fire Mario Gotze, naming the Germany international in his attack alongside Robert Lewandowski and Mitchell Weiser.
The first chance fell to Gotze on the edge of the area after two minutes, but he scuffed his shot and saw it easily saved.
A fast break from Freiburg put Jonathan Schmid through on goal after eight minutes. He tried to beat Juan Bernat, but the Spaniard did enough to put him out of his stride and the shot was tame in the end.
Bayern had the ball in the net a minute later when Mehdi Benatia converted a corner with a header, but the referee spotted an infringement and disallowed it.
The deadlock was finally broken when Weiser executed a great piece of skill after 13 minutes, controlling a long pass before jinking past Christian Gunter on the right wing and playing a simple pass into the box that the unmarked Schweinsteiger gratefully slotted into the net.
Jerome Boateng stung the palms of Freiburg goalkeeper Roman Burki with a thumping header from Xabi Alonso's corner as Bayern looked to be on cruise control, but Freiburg hauled their way back into the game in the 33rd minute.
Felix Klaus took advantage of some sloppy play from the visitors, intercepting a loose pass and flicking the ball to Mehmedi, who advanced to the edge of the box and rattled a low shot into the corner of the net, giving Manuel Neuer no chance.
Freiburg went close to taking the lead at the start of the second half when Schmid crossed and Mehmedi felt he was pushed to the ground by Rafinha as the ball flashed across the face of Neuer's goal, but the referee waved play on, much to the dismay of the Freiburg players and coaching staff.
Guardiola sent on Thomas Muller for Alonso as he urged his side to go for the win, and Schweinsteiger shook the crossbar with a looping free-kick.
Freiburg went close through Gunter in the final stages of a spirited performance, and steadily built momentum.
And just as it looked as though their Bundesliga survival battle would yield only a point, Petersen struck.
Bayern were caught ball watching around the half way line and Karim Guede took advantage, stealing possession and sending a perfect cross to the substitute, who made no mistake with only Neuer to beat.