Having cruised to a 3-0 lead at the break thanks to Mario Gomez's first-half hat-trick, Bayern were left rattled as Argentina defender Federico Fernandez scored the second of two headers with ten minutes left to set up a tense finale.
Bayern's victory came at a heavy price as Germany star Bastian Schweinsteiger was stretchered off in the second half with a broken collar bone which will keep him out for several weeks and he faces an operation on Thursday.
Gomez's treble means he has now scored 19 goals in all competitions this season for Bayern and this was the ninth time he has scored three goals or more for Munich since joining from Stuttgart in 2009.
"We put in an exhilarating first-half, that was real fun," said Gomez. "I was lucky enough to be the one in the middle for the three goals."
After Manchester City's win over Villarreal in Spain, Bayern are now three points clear at the top of Group A with two games remaining.
Defeat means Napoli drop to third in the table and will be without Colombia winger Juan Zuniga for their next game at home to City on November 22 after he was sent off after receiving a second yellow card.
"We turned things around well, but at the end it wasn't enough to influence
the result," said Napoli coach Walter Mazzarri. "We created several good chances in the second half, but we just couldn't convert them. The result wasn't what we deserved, but I am happy with the performance.”
Bayern opened the scoring on 17 minutes when Gomez turned his defender and smashed his shot past Napoli goalkeeper Morgan De Sanctis.
The 26-year-old then left the Italians reeling when he netted his second just six minutes later.
A long-range pass from Germany colleague Toni Kroos found him unmarked at the far post and with the Napoli defence desperate for him to be offside, the flag stayed down and he volleyed home to make it 2-0 after just 23 minutes.
To add injury to insult, while Napoli struggled to get a replacement on for injured defender Salvatore Aronica, the hat-trick was completed on 41 minutes when De Sanctis parried a Kroos shot and Gomez had an easy tap in.
Napoli started the fight-back when Fernandez headed home on 45 minutes.
It was the first time Bayern have conceded a goal in Munich since August 7, having scored 36 goals in the process.
Napoli were reduced to ten men when Zuniga hauled down Ribery on 70 minutes, just a minute after earning his first yellow for a similar offence and referee Bjorn Kuipers had no hesitation in giving him a second booking and the red card.
Holger Badstuber followed soon after for a heavy foul on Edinson Cavani on 77 minutes, which saw him earn his second yellow of the game before Fernandez struck again to set up a tense final ten minutes.