Sam's winning goal, which arrived three minutes from time, sealed the visitors' first win in Munich in 23 years and brought an end to the Bavarians record eight-game winning streak.
Stefan Kiessling handed Leverkusen a first-half lead, before Bundesliga top scorer Mario Mandzukic levelled in the 77th minute with his eighth goal of the season.
The result left Bayern on 24 points with Schalke 04 moving into second place after edging past Nuremberg 1-0 on Saturday.
"This defeat will not derail us," said Bayern coach Jupp Heynckes. "But we have to draw our lesson from this game. We should be playing over 90 minutes the way we played in the second half."
Earlier on Sunday, Eintracht Frankfurt lost 2-1 at VfB Stuttgart to drop to third place on 19, with champions Borussia Dortmund in fourth, four points behind.
Bayern needed just two minutes to show they meant business, coming perilously close with a cheeky flick from Bastian Schweinsteiger that sailed narrowly wide of the post.
The Bavarians, without injured Franck Ribery and Javi Martinez but with Arjen Robben back on the bench after a month out with a back problem, kept up a barrage of attacks in a largely one-sided half.
Leverkusen keeper Bernd Leno was soon called into action, saving a point-blank header from Bayern top scorer Mandzukic who rose high in the box to meet a well-timed Holger Badstuber cross.
The visitors, however, scored against the run of play when Kiessling, looking to win back a spot in the Germany squad, rounded off a swift counter-attack for his sixth goal of the campaign.
Bayern brought on the diminutive Xherdan Shaqiri and Robben in the second half and the visitors were quickly on the backfoot again, soaking up pressure and waiting for a chance to break.
Leno was in good position to block a long-range Shaqiri shot but he could do nothing when substitute Claudio Pizarro chipped a cross into the box and Mandzukic drilled in for the equaliser.
Sam clinched an unlikely victory when his header was deflected in off Boateng while Bayern's Pizarro hit the bar at the death.
"I liked the way the team worked in this game," Leverkusen coach Sascha Lewandowski told reporters. "We are on the right path and this became clear with today's special win although we were under a lot of pressure in the second half."
Stuttgart striker Vedad Ibisevic scored his fifth goal in six games to help his team beat Frankfurt and notch their first home win of the season.
Missing half a dozen players through injury, Stuttgart took a sixth minute lead with Christian Gentner volleying in a deflected Ibrahima Traore cross at the far post.
Eintracht levelled with Alexander Meier, who had earlier missed a first-half header from five metres.
Meier's goal brought a smile to Eintracht manager Armin Veh's face, but that soon disappeared when Bosnia international Ibisevic's header in the 84th minute gave Stuttgart victory.
Stuttgart's win moves them up to eighth on 12.
Borussia Monchengladbach also scored a memorable victory, coming from two goals down to beat Hannover 96 3-2 and move further away from the relegation zone.
Get the best features, fun and footballing frolics straight to your inbox every week.
Thank you for signing up to Four Four Two. You will receive a verification email shortly.
There was a problem. Please refresh the page and try again.