Papy Djilobodji's goal with just three minutes of the season remaining saw Werder Bremen climb out of the relegation playoff berth at the expense of opponents Eintracht Frankfurt with a 1-0 win at the Weserstadion.
Frankfurt, who only needed a draw to avoid a play-off to stay in the Bundesliga, defended resolutely until Djilobodji's second goal of the season sparked wild celebrations in Bremen.
The win lifted them up to 13th and left Frankfurt to face Nurnberg, who finished the season third in the second tier, in a two-legged play-off to avoid the drop.
Claudio Pizarro, potentially playing his last game for Bremen, had an early sight of goal but there was an even better chance for Anis Ben-Hatira at the other end which Felix Wiedwald did well to get down to and push wide.
Wiedwald had to make another excellent save with a strong right arm to deny Makoto Hasebe in the 20th minute as Frankfurt threatened to take the lead on the counter-attack, having soaked up some Bremen pressure.
Pizarro did not get enough on a header from six yards out and Zlatko Junuzovic sent a free-kick over as Bremen increased the pressure.
It was almost one-way traffic, but Bremen were unable to find a way through the massed defensive ranks of Frankfurt players and, with 45 minutes of the season left to play, the northern Germany side were still occupying a relegation play-off berth.
They needed a goal to avoid that and they pushed intently for it in the second half, with Junuzovic uncharacteristically slicing a shot wide at the far post.
Frankfurt coach Niko Kovac reinforced his defence by bringing defender Carlos Zambrano on for forward Ben-Hatira, setting up a tense final 25 minutes.
The tension grew by the second up to the 88th minute when Djilobodji slid in to ensure Theodor Gebre Selassie's effort crossed the line, and lifted the roof off the Weserstadion.
There was delirium at the final whistle as Bremen's place in the Bundesliga next season was confirmed, and Frankfurt's campaign was sent into extra-time.