Former Germany striker Mario Gomez scored in his final game for Stuttgart, whose vastly superior goal difference made promotion all but guaranteed heading into the final weekend of the season.
Stuttgart secured second place behind champions Arminia Bielefeld, 3-0 winners over Heidenheim who will contest the promotion/relegation play-off against Werder Bremen after Hamburg failed to capitalise on their rivals' defeat.
Hamburg, an ever-present in the Bundesliga before their relegation in 2018, ultimately needed just a point at home to mid-table Sandhausen to climb above Heidenheim but crashed to a humiliating 5-1 loss.
Heidenheim, who scored two late goals in last weekend's 2-1 win over Hamburg, will travel to Bremen for the first leg of their play-off tie on Thursday, with the return fixture set for July 6.
Heidenheim have never played in the Bundesliga and were in the fifth tier as recently as 2008, while Bremen are the longest-serving club in the top flight having spent all but one season there since its inception in 1963.