The visitors, who have now failed to score on all three of their league visits to the Allianz Arena, could have leapfrogged their rivals into third with victory but succumbed to substitute Ribery's 83rd-minute strike.
Both sides finished with 10 men after Stefan Ilsanker and Renato Sanches were sent off in injury time.
The three points moved Bayern to within six points of leaders Borussia Dortmund, who face second-placed Borussia Monchengladbach on Friday.
In a tight game, there was not a clear sight of goal for either side until the 24th minute, when Peter Gulacsi came to Leipzig's rescue with a superb save.
Robert Lewandowski was ruled to be onside when he ran through and collected Serge Gnabry's pass. His shot looked to be heading for the bottom corner but Gulacsi's fingertips pushed the ball onto the inside of the post, from where it rolled along the goal-line and out for a corner.
Gnabry looked a real threat so it was a blow for Bayern when he pulled up a couple of minutes later and had to be replaced by Ribery.
Leipzig looked comfortable and they came agonisingly close to opening the scoring in the 36th minute.
Young defender Dayot Upamecano, who is still searching for his first Bundesliga goal, met Kevin Kampl's corner with a towering header that beat Manuel Neuer but crashed against the crossbar.
Timo Werner is reported to be a January target for Bayern and he made his presence felt, although he was unable to keep a volley down early in the second half.
Clear-cut chances remained hard to come by. Sanches, on for Kingsley Coman, should have done better when the ball dropped to him on the edge of the penalty area than pull a shot well wide.
Bayern were beginning to look the side more likely but still they could not find the decisive moment.
Gulacsi's flap gave Niklas Sule a chance but he could only shoot wastefully over, then the Leipzig keeper performed more heroics by clawing away Joshua Kimmich's header.
The wide man looked certain to score when Lewandowski headed across goal but Gulacsi sprang to his left to preserve parity.
Gulacsi then blocked from Sanches but this time he could not hold the ball and a rushed clearance fell to Ribery, who coolly cut inside before firing into the net.
Yussuf Poulsen had a great chance to level almost immediately, with a Kampl corner again causing problems for Bayern, but the Dane headed wide.
The game ended on a sour note when Ilsanker and Sanches were both dismissed.
Ilsanker had barely been on the pitch for 10 minutes when he slid in recklessly on Thiago Alcantara. Sanches responded by pushing the midfielder to the ground and was also shown a red card.