Mario Gomez put the Bavarians in front in the ninth minute, but Papiss Cissé deservedly levelled for the hosts within ten minutes, shortly after missing a penalty.
The home side looked capable of taking all three points until Franck Ribery scored in the 88th minute to save Bayern's blushes and keep them just two points behind third-placed Hannover. "It was important that we came here and got the win," said Ribery. "Now we have to keep working hard and keep winning."
Bayern made a flying start with the league's top goalscorer Gomez putting them ahead after only nine minutes. He met Franck Ribery's free-kick with his head to score from ten yards out and move onto 19 Bundesliga goals for the season.
His nearest challenger for the golden boot award is Cisse, who had a perfect chance to reply in the 14th minute when Freiburg were awarded a penalty for a foul by Bayern goalkeeper Thomas Kraft on Cedric Makiadi.
However, the Senegalese striker's weak shot was saved by Kraft. He made up for his mistake just three minutes later to bring Freiburg level with a better shot from a moving ball from ten yards, taking him onto 18 goals for the season.
The sight of Arjen Robben leaving the field after only half an hour was a further blow to Bayern's hopes of getting all three points. And they could have been behind ten minutes before the break when Daniel Caligiuri's shot struck the inside of the post and Makiadi was not quick enough to react to the rebound.
Freiburg were the better team in the second half too with Makiadi going close to putting them in front in the 58th minute with a shot into the side-netting. But their failure to score a second came back to haunt them when Ribery grabbed a winner for Bayern two minutes from time.
The Frenchman cut in from the left and shot with his right foot, from fully 25 yards out, into the far bottom corner of Oliver Baumann's goal to steal a crucial win for Bayern in view of Hannover's win over Hoffenheim.
Fre - Bay GOALS www.rojadirecta.es by kehl3