It was Leipzig’s first ever win over the Bavarians and moved them up to 43 points in sixth place and within striking distance of a top four finish.
During a weekend when Bayern could have wrapped up the title with seven matches to spare, the champions ended up having their lead at the top of the Bundesliga standings cut to 17 points after second-placed Schalke 04 beat Wolfsburg 1-0 on Saturday.
Defeat for Schalke would have meant Bayern would have secured a sixth successive Bundesliga title had they beaten Leipzig on Sunday.
The treble-chasing leaders remained on 66 points with Schalke on 49 and third placed Borussia Dortmund on 48.
“We faced an outstanding opponent today,” said Bayern coach Jupp Heynckes, whose team face Sevilla in the Champions League quarter-finals next month.
“We have to recognise that. Leipzig were aggressive and were playing good pressing.
“We did not play like in the past few weeks. There are these games where you are not as dominant and not as hard-working in defence.”
Bayern striker Sandro Wagner confirmed his fine form, heading in a perfect James Rodriguez cross in the 12th minute to score for the third straight game in all competitions as he vies for a spot on Germany’s World Cup squad.
But after that Keita, who will join Liverpool at the end of the season, took over for Leipzig, levelling in 37th minute by scoring on the rebound after Timo Werner’s effort was blocked.
He then caught the Bayern defence napping and sent the Germany striker through for the winner in the 56th in what was Bayern’s third league loss of the season.
Dortmund’s Michy Batshuayi scored a spectacular first-half winner to lead his team to a 1-0 home victory over Hanover 96 that kept them on course for a top-three Bundesliga finish.
The 24-year-old Belgium striker, who arrived on loan from Chelsea in January, grabbed his sixth Bundesliga goal in seven games with an eye-catching backheeled volley in the 24th minute from a corner.
Batshuayi also hit the woodwork at the start of the game as did team mate Maximilian Philipp late on.
It was by no means a dominant performance from Dortmund, who exited the Europa League in midweek, but it was enough to lift them to one point behind Schalke.
The top four teams qualify automatically for the Champions League group stage next season.