The 31-year-old Polish international has scored 191 goals for the German champions since moving from Borussia Dortmund in 2014.
"I'm convinced that we'll achieve a lot in the next few years, Bayern is one of the top three clubs in the world and we have a great team and I'm proud to be part of that club," Lewandowski said.
The German top-flight's top-scorer in four of the last six seasons, Lewandowski has begun the season in dynamic form scoring a brace on the opening day of the campaign and adding a hat-trick against Schalke last weekend.
Bayern chairman Karl-Heinz Rummenigge expressed his delight at keeping the goalscoring heir to Gerd Muller and himself at the club.
"Robert is the best centre-forward in the world in my opinion and has been a key player in our team for many years," Heinz Rummenigge said.
"We are delighted that he will be playing for Bayern for a long while yet."