Gnabry had started courting interest from Premier League clubs like Liverpool, Chelsea and Manchester United after entering the final year of his Bayern Munich contract.
With Bayern set to lose top marksman Robert Lewandowski to Barcelona, the club have acted fast to secure the future of the German international.
Gnabry joined Bayern Munich from Werder Bremen in the summer of 2017 and was immediately sent on a season-long loan at Hoffenheim.
He returned to Bayern the following season and has since developed into a key player for the Bavarians, making 171 appearances for the club and scoring 64 goals.
Gnabry has won the Champions League, four Bundesliga titles, two DFB-Pokals, the UEFA Super Cup and FIFA Club World Cup in his time with Bayern.
"I thought a lot about what I want as a player in the coming years, and came to the conclusion that I want to stay at FC Bayern, win everything again here and experience things - in particular celebrating another Champions League title, but this time with our fans," Gnabry told the club's official website.
"It's special because I get to play here with my friends at the highest level. It certainly wouldn't feel the same at a different club. I want to experience more great moments here - and nowhere else. The hunger for major honours isn't going away."
Bayern CEO Oliver Kahn added: "With his spectacular style of play, Serge Gnabry is a player who fans come to watch. We're glad that he's extended his contact and look forward to him continuing to be an important part of our team."
"Serge came to Munich at the age of 22 and has grown into a Champions League winner and international here. We need top international players like him to achieve our big objectives."