Elsewhere in Saturday's programme, Union Berlin and Bochum played out the final minutes of a 1-1 draw without attacking, after Bochum's goalkeeper was struck by an object thrown from the stands.
With Kane out injured, Bayern struggled to generate scoring chances as Lee Jae-sung gave Mainz a two-goal lead.
Coach Bo Henriksen celebrates with Anthony Caci after Mainz's unlikely win over Bayern. (AP PHOTO)
Leroy Sane scored on the rebound in the 87th minute to give Bayern hope of a comeback, but Kompany's team could not find a second goal.
Bayern's lead was cut to four points ahead of last season's champions Bayer Leverkusen.
While Bayern had painful losses in the Champions League to Aston Villa and Barcelona and were knocked out of the German Cup by Leverkusen last week, they had seemed well on course to reclaim the Bundesliga title - until now.
Bayern's defence were at fault for both goals, with the first coming after Kim Min-jae missed his interception of a cross and Michael Olise couldn't control the ball, allowing Armindo Sieb to set up Lee to score.
The second goal again saw Sieb pass for Lee, who left Joshua Kimmich stranded with a turn and scored low past stand-in goalkeeper Daniel Peretz.
Sieb was on the field only because starting forward Jonathan Burkardt went off injured in the 15th.
Mainz coach Bo Henriksen jumped for joy when the final whistle sealed a win over Bayern, who had beaten his team 8-1 last season.
The Union Berlin-Bochum game finished with players passing the ball to the opposition and milling around in the centre of the field as the teams agreed to run down the clock.
The game was stopped when Bochum goalkeeper Patrick Drewes was hit by an object — seemingly a cigarette lighter — from the stands.
Players were off the field for nearly half-an-hour while he was treated and they discussed whether to play out the time remaining, about three minutes.
The draw delivered a valuable point for last-placed Bochum, who have yet to win this season.
After a slow start to the season, Leverkusen's 2-0 win at Augsburg was their seventh in a row in all competitions.
Leverkusen could thank winger Martin Terrier for his first goal since September and some skill from Florian Wirtz, who scored the second goal just before half-time with a low shot through a defender's legs.
Borussia Moenchengladbach also beat Holstein Kiel 4-1, while St Pauli were hosting Werder Bremen later on Saturday.