A Sejad Salihovic penalty gave the guests the lead early on, but Stefan Kiessling pulled Leverkusen level.
Kevin Volland immediately restored Hoffenheim's lead, which they took into the break before being pegged back once again by Simon Rolfes.
Anthony Modeste then grabbed a last-gasp winner for Markus Gisdol's side, earning them one of their sweetest wins of the season, particularly in view of what happened in Sinsheim earlier this season.
Back then, a Kiessling header which entered the goal through a hole in the side netting helped Leverkusen to a 2-1 win.
Eintracht Frankfurt took a big step away from the relegation zone by claiming a convincing 5-2 win over fellow strugglers Nurnberg.
Tranquillo Barnetta gave Armin Veh's men the lead and further goals from Joselu and Alexander Madlung put them in command of the game.
Nurnberg, who had Javier Pinola sent off, mounted a spirited recovery with Josip Drmic and Jose Campana bringing them back to within sight of the draw, but two late goals from Joselu and Vaclav Kadlec sealed Frankfurt's win.