Lewandowski missed a sitter midway through the second half but made no mistake in the closing stages and Bayern were worthy of their victory.
The hosts did the majority of the attacking in the match, created the better chances, and had the star performer in the shape of their new signing Douglas Costa, a Brazilian international.
The 2015/16 season is looming but the tackles were flying in nonetheless during a competitive first half, Marcelo and Xabi Alonso both picking up bookings.
Keylor Navas had a good night in the Real goal and kept out first half efforts from David Alaba and Mario Gotze, who was brilliantly set up by Costa.
Navas was wrong-footed at one point when a Thomas Muller shot deflected off Sergio Ramos but the post came to Real’s rescue.
Bayern continued to hold sway after the break, although Manuel Neuer did have to pull off a pair of good saves to deny his Germany team-mate Toni Kroos.
At the other end, Costa surged down the left and crossed low to Lewandowski but the Pole somehow missed the target with the goal gaping.
But he was more clinical two minutes from time, getting on the end of Costa’s well-delivered free-kick and turning the ball past Navas from close range to delight the Bayern support.
Real were without Cristiano Ronaldo, who did not travel to Munich for the tournament, and Gareth Bale, who did not come off the bench.