Fellow Champions League competitors Schalke slumped out of the competition in a 2-1 defeat by visiting Mainz, while Bundesliga side Fortuna Dusseldorf were stunned 2-0 by third-tier Kickers Offenbach.
Bayern, who also lead the Bundesliga at the start of the winter break, grabbed the lead against the run of play with striker Mario Gomez tapping in from close range.
But things took a turn for the worse at the start of the second half when winger Ribery slapped South Korea's Koo Ja-cheol and received a straight red card.
In an entertaining second half both sides missed several good chances, with Mario Mandzukic, who has failed to score since the return of Gomez in November, twice coming close for Bayern.
Xherdan Shaqiri, who had earlier hit the crossbar, settled the visitors' nerves five minutes from time, slotting in after good play from Mandzukic and Thomas Mueller to ensure Bayern finished the year on a high.
"Overall I am satisfied with our season so far because we have been playing very well over long periods," Bayern coach Jupp Heynckes said. "It cannot really get much better than that."
"As for the red card, it was provoked but as a Bayern player you must know how to handle such situations," he said.
With new Schalke coach Jens Keller, who replaced Huub Stevens on Sunday, making his debut, the hosts showed few signs of recovery in the cup after losing four and winning none of their last six league games.
Schalke, who topped their Champions League Group to book a spot in the next round of Europe's premier competition, allowed the visitors to take a 30th-minute lead when Marco Caligiuri drilled in from 16 metres.
After a string of missed chances, Dutch striker Klaas-Jan Huntelaar drew them level but their joy was short-lived as Nicolai Mueller controlled a Jan Kirchhoff cross to fire in the winner seven minutes from time.
Schalke's Christian Fuchs rattled the bar late in the game but could not prevent the 2011 Cup winners' exit in their sixth straight game in all competitions without a win.
"The team was insecure in the first half and you could see it," Keller said. "I liked how we played in the second but still we are hugely disappointed."
Freiburg advanced with a 1-0 victory over third-tier Karlsruhe SC but the shock of the night was Kickers Offenbach's surprise 2-0 victory over Fortuna Dusseldorf.
The lowly third tier club hung in until the 76th minute when the Fortuna defence failed to clear a cross and Mathias Fetsch scored on the rebound after an initial save by the keeper.
Stefan Vogler darted into the box and added another five minutes from time to complete another upset for Offenbach, who beat teams from higher divisions in the previous two rounds.
Holders Borussia Dortmund face Hannover on Wednesday.
- Sports & Recreation
- Fortuna Dusseldorf
- Kickers Offenbach
- Mario Gomez