Javi Martinez’s brave header consigned Celtic to defeat and ended the Scottish champions’ hopes of reaching the Champions League’s knockout stage.
Bayern Munich took the lead in the first half when Kingsley Coman pounced after Dedryck Boyata’s hesitation.
The home side played valiantly and were rewarded by Callum McGregor’s equaliser after the break at Celtic Park.
The scoreline was only level for four minutes, with Martinez suffering a cut as he headed the winner.
With Paris St-Germain defeating Anderlecht 5-0 in the other Group B game, Celtic cannot finish in the top two positions, although they have an advantage over the Belgian side in the race for third and participation in the Europa League knockout stages.
Bayern were shorn of some of the key men in their defeat of Celtic a fortnight ago in Munich, with Robert Lewandowski, their goal-scorer in chief, and Thomas Muller, their rangy schemer, both injured.
Bayern’s manager Jupp Heynckes – with an eye on the Bundesliga meeting with Borussia Dortmund at the weekend – also relegated Mats Hummels, Thiago Alcantara and the hugely-influential Joshua Kimmich to the bench.
That said, they were hardly threadbare. Kingsley Coman, James Rodriguez and Arjen Robben were the front three while Martinez, a Spanish colossus, also came back into the team.
Celtic had not won a home group game in Europe in three years coming into the game, a stretch that comprised six losses and three draws – a run that does nothing to add to the legend of Celtic Park as a European fortress.
There was pressure on them to at least perform and take Bayern to the wire by making a proper game of it.
From early on you sensed they had it within them to do it. Their passing was crisp, the intensity high and their threat genuine. Bayern, by contrast, were way below their customary level.
Brendan Rodgers went with a 3-4-2-1 that became 5-4-1 when required. James Forrest and McGregor were whirling dervishes in attack and defence, buzzing about, breaking play up and then roaring forward on the attack.
Up front on his own, Moussa Dembele had a real presence.
Rodgers’ team should have been ahead as early as the third minute, a lusty intervention from Kieran Tierney turning defence into attack.
Forrest took it up from there, dinking a cross to the back post where Stuart Armstrong looked sure to score, but the Scotland man side-footed wide of the post.
Celtic continued to take the game to Bayern, with Forrest, McGregor and Dembele all causing problems and the home crowd revelling in their side’s display and the feeling something special was going to happen.
There was no gathering dread with Bayern peppering Craig Gordon’s goal or clever movement cutting Celtic open, and indeed the opening goal came from an agricultural punt downfield from Bayern goalkeeper, Sven Ulreich, that should have been dealt with comfortably by Boyata.
The Belgian let the ball drift over his head and Coman was onto it – and around the stranded Gordon, who screamed the Frenchman had handled the ball – in the blink of an eye.
Play went on and Coman threaded a shot between retreating defenders to give Bayern a lead they scarcely deserved.
The response was impressive. Armstrong and Dembele worked a great opening and only a fine tackle by David Alaba stopped the Frenchman from levelling. Next, after terrific work by Forrest in setting up Armstrong, it was Ulreich who denied Celtic.
The equaliser did come, though, and it was hardly a surprise it was Forrest who created it and McGregor who finished it.
The midfielder drilled his shot between Ulreich’s legs but the home support’s collective heart-rate had barely returned to normal before Bayern went ahead again.
Again, it was desperately soft. Alaba curled in a cross from the left and Martinez rose above Bitton to head past Gordon.
For all the improvements in their performance and all the electricity inside the stadium, it still amounted to defeat.
This was a lot better from Rodgers’ men, but it wasn’t enough to keep them in the hunt for the last 16. Now, it’s all about nailing down a Europa League place.