The 23-year-old confirmed on Tuesday that he will sign for Bayern upon his return from China and the United Arab Emirates.
"I look forward to joining Bayern Munich and I want to help the club attack the German championship next season and look forward to playing in the Champions League," said Gomez, who has 23 caps for Germany, in a statement.
Gomez scored 24 goals last season and has regularly led Stuttgart's attack.
"The club is really happy that Mario Gomez has decided to join us," said chairman Karl-Heinz Rummenigge.
"He is a first-class striker who has scored around 20 goals per season in each of the last three years to prove he is one of the best strikers and we look forward to having him with us."