Top three triumph to keep Bundesliga race tight
The top three all have 40 points after 19 games.
Bayern's Bundesliga top scorer Mario Gomez scored from five metres to break the deadlock on the hour with his 17th league goal this season and Arjen Robben added another in added time.
It was certainly not the performance Bayern fans were expecting after the defeat by Borussia Monchengladbach last week and a midweek PR stunt regarding a "spectacular signing" that backfired when it turned out to be a promotional gimmick.
The hosts, chasing a treble this season, looked far from sharp despite the return from suspension of winger Franck Ribery.
Gomez missed a golden opportunity to grab an early lead and Thomas Muller wasted another late in the first half before the Germany international scored on the rebound after his header from a Toni Kroos free-kick was blocked on the hour.
Bayern needed to wait another 30 minutes to make sure of their first league win this year with substitute Ivica Olic breaking free in stoppage-time, lobbing a ball over charging goalkeeper Diego Benaglio and Dutchman Robben scoring on the line.
"For me it was a highly deserved win based on our chances," Bayern coach Jupp Heynckes told reporters. "It was not easy after the defeat against Gladbach. This gives us security going into the coming weeks."
Dortmund stayed hot on Bayern's heels with Japanese midfielder Shinji Kagawa scoring twice and Kevin Grosskreutz adding another as they eased past Hoffenheim.
Kagawa grabbed a 16th-minute lead and Grosskreutz doubled it in the 31st s Dortmund quickly took control of the match.
The Japanese added another goal 10 minutes after the restart, firing in from close range after a fine one-two with Grosskreutz. Fabian Johnson cut the deficit for the visitors.
Schalke kept pace with the leaders thanks to a comfortable win at Cologne secured with four goals in 22 minutes late in the second half as they came from behind after Lukas Podolski had given the home side the lead in the fourth minute.
Ciprian Marica scored in the 60th and 72nd minutes for Schalke before Klaas Jan Huntelaar converted a penalty in the 78th and Marco Hoeger wrapped up the win in the 82nd.
Champions League competitors Bayer Leverkusen came from a goal down to draw 1-1 at Werder Bremen with Michael Ballack kept on the bench after criticism from club bosses this week. They stayed in sixth place on 30 points, one behind their opponents.
Hamburg SV recovered from last week's 5-1 mauling by Dortmund to beat Hertha Berlin 2-1 and move up to 11th on 22.