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.
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.
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 Moenchengladbach also scored a memorable victory, coming from two goals down to beat Hanover 96 3-2 and move further away from the relegation zone.