Midfielder Wataru Endo scored in stoppage time for Stuttgart to clinch Bundesliga survival at Hertha Berlin's expense after a dramatic 2-1 win over Cologne in the final league match of the season on Saturday.
Endo's 92nd-minute winner lifted Stuttgart ahead of Hertha on goal difference to set off scenes of jubilation with fans storming the field.
Hertha lost at Borussia Dortmund 2-1. Youssoufa Moukoko's late winner for Dortmund sent Hertha into the dreaded relegation playoff against the second division's third-place finisher to see which will play in the Bundesliga next season.
Hertha will likely face former Bundesliga heavyweight Hamburg on May 19 and 23.
On a day of farewells in the Bundesliga, Erling Haaland also scored for Dortmund and Robert Lewandowski brought his league-leading tally to 35 goals for Bayern Munich, while Arminia Bielefeld was finally relegated to join last-placed Greuther Furth in the second division.