After spending much of the season in the dropzone, Werder was fighting for its life in Germany's top flight as the club that has played more top-flight matches than any other, including Bayern Munich.
2. Bundesliga's Heidenheim, meanwhile, was looking for a place at the top table after an astonishing rise from the country's fifth tier, where it was playing its football barely a decade ago.
It seemed six-time champion Werder Bremen would have an easy ride when a calamitous own-goal by Norman Theuerkauf put the visitors ahead inside the opening three minutes, slicing an attempted clearance past Kevin Muller in the Heidenheim goal and into the top corner.
Bremen, however, failed to make the most of other clear-cut chances in the first half, most notably Davy Klaassen spurning a free header, and the score remained unchanged at the interval.
Two changes from Heidenheim manager Frank Schmidt proved inspiring and the hosts came charging out of the blocks after the break, burying Werder Bremen under a flood of chances.
Both Stefan Schimmer and David Otto went desperately close to finding an equaliser inside the opening minutes of the second half, and it seemed almost certain that Werder's resistance would crumble.
At the other end, Muller was making stunning saves, denying Yuya Osako a couple of times, and American Josh Sargent in a one-on-one.
Bremen became increasingly frustrated as the chances failed to go in, and five minutes from time, the game was level when a stinging long-range drive from Tobias Mohr cannoned off the bar and into the path of Tim Kleindienst, who tapped into an empty net.
Needing to secure a goal to secure victory, Heidenheim threw everything forward, and would pay the price four minutes into stoppage-time when Ludwig Augstinsson fired into an empty net after Fin Bartels escaped a tired defence to draw out Muller and feed his on-rushing team-mate the simplest of chances.
A penalty for the hosts was converted by Kleindienst in the 98th minute, but he knew the game was up before he took it, and Bremen burst into rapturous celebration as broken-hearted Heidenheim was left to wonder what might have been.