Gomez, 32, came through the Stuttgart youth system and won the 2007 Bundesliga title with the club.
“I am very happy to return home, to the place where it all began,” he said.
The transfer fee was around three million euros ($3.5 million), according to German sports agency SID.
Gomez has scored 151 Bundesliga goals and has played 71 times for Germany, scoring 31 goals.
“With Mario Gomez, we will have a scorer of the highest quality,” Stuttgart’s sporting director Michael Reschke said.
Germany coach Joachim Loew left Gomez out of his 2014 World Cup squad, but recalled him for Euro 2016.
Gomez abruptly left Besiktas in 2016 after the coup attempt against Turkish President Recep Tayyip Erdogan and joined the Volkswagen-backed Wolfsburg side.
Download our app and read this and other great stories on the move. Available for Android and iOS.