It is only Gladbach’s third win in Munich in 47 league games and lifts Lucien Favre’s side back to third in the table.
Despite the defeat, Champions League quarter-finalists Bayern still hold a 10-point lead at the top of the table and are on course for a third straight league title.
Raffael, who turns 30 next Saturday, profited from a rare mistake by Manuel Neuer to give the visitors the lead as the keeper failed to block the Brazilian’s long-range shot as it rolled into the goal with half an hour gone.
Gladbach claimed their second on 77 minutes when Germany midfielder Christoph Kramer squared for Raffael to fire his second past Neuer.
There was more bad news for Bayern coach Pep Guardiola as Dutch winger Arjen Robben was forced off in the first half and taken to hospital – he also missed last week’s win at Werder Bremen with a trapped nerve.
Earlier, second-placed Wolfsburg were held to a surprise 1-1 draw at mid-table Mainz after the hosts took a shock seventh-minute lead when defender Niko Bungert out-jumped the visiting defence to head home from a corner.
Wolfsburg made their possession count as Brazil midfielder Luiz Gustavo hit the post, then scored their equaliser on 61 minutes, but they could not grab a winner.