Pigsty murders: Zachariah Olivier to spend Christmas in jail [VIDEO]
Keita, who will join Liverpool in the summer, was shown a yellow, then a red card in quick succession late on for fouling Mainz scorers Alexandru Maxim and Bote Baku, who made his debut.
The 23-year-old Keita stormed off the pitch and will be suspended for Saturday’s home match against Wolfsburg.
It was the defensive midfielder’s third red for Leipzig in 2017/18.
He was also sent off for Guinea in a World Cup qualifier against Tunisia, the first of two red cards he earned last October before being dismissed in Leipzig’s German Cup defeat to Bayern Munich.
This was Leipzig’s fifth game without a win and leaves them sixth in the table, just hanging on to a Europa League berth.
Mainz boosted their survival hopes as Maxim and Baku hit late goals after Pablo de Blasis netted a first-half penalty.
Victory lifted Mainz out of the bottom three and into 14th with a three-point buffer from the relegation places.
Wolfsburg replaced them in 16th which carries a two-legged play-off at the end of the season against the team which finishes third in the second division.
Leipzig wasted a golden early chance when Ademola Lookman, on loan from Everton, pounced on a mistake, but Yussuf Poulsen could only fire wide.
Less than 60 seconds later, Germany striker Timo Werner had a shot blocked as RB kept attacking.
However, Mainz took the lead against the run of play when de Blasis converted a penalty on 29 minutes.
The hosts were awarded the spot-kick after Japan striker Yoshinori Muto was sent tumbling in the area.
RB Leipzig had chances to pull a goal back, but Mainz kept pushing for a second goal and deserved to go 2-0 up five minutes from time.
Just after coming off the bench, Romanian midfielder Maxim fired home when the ball landed at his feet from a cross.
De Blasis sprinted back off on to the pitch to join the celebrations having just come off.
The fairytale win was complete when Baku, 20, who has risen up through the ranks from the club’s Under-10 team, scored on his debut.
The midfielder outsprinted Leipzig defender Dayot Upamecano to cooly fire home in the 90th minute to the delight of the Mainz bench.
The win does not guarantee Mainz’s survival, but is a big step towards safety with matches against Borussia Dortmund and Werder Bremen to come.
Download our app and read this and other great stories on the move. Available for Android and iOS.