Lewandowski's first-half goal put Bayern on track and when Thomas Muller added their second after the interval at Weser-Stadion on Wednesday they seemed set to cruise into a final against RB Leipzig in Berlin.
But Werder hit back with Yuya Osako and Milot Rashica on target with a quickfire double to briefly draw them level before Lewandowski converted a controversial penalty in the 80th minute to win it.
Bundesliga leaders Bayern suffered a shock loss to Niko Kovac's Eintracht Frankfurt in the final last year but, despite Lewandowski missing an open goal for his hat-trick in added time, the coach now has a chance to potentially make it a double in his first season in charge of the Bavarian giants.
Muller, appearing in his 10th DFB-Pokal semi-final, nearly scored an early opener for Bayern with a clever backheel from Kingsley Coman's low cross.
Osako fired wide and Davy Klaassen missed a good volleyed chance at the other end but Bayern's pressure told in the 36th minute as Muller's looping header came back off the post and Lewandowski tucked away the rebound.
Lewandowski soon had the ball in the net again, glancing in Muller's cross - the goal ruled out for offside - but Bayern would not be denied in the 63rd minute.
Muller collected a shot from Leon Goretzka and fired past Jiri Pavlenka, at which point there were few signs of a Werder recovery.
But Osaka drilled in and straight from kick-off Bayern surrendered possession cheaply, Rashica embarking on a superb solo run that ended with a brilliant finish across Sven Ulreich.
Parity was short-lived, however, with referee Daniel Siebert harshly pointing to the spot when Coman seemed to go down easily in the box under Theodor Gebre Selassie's challenge.
Lewandowski, who scored twice off the bench to see off second-tier Heidenheim in the last round, coolly stroked the penalty home but then hit the woodwork with the goal gaping from two yards out, as a somewhat fortunate Bayern progressed to the final.
What does it mean? Double chances alive for Bayern
Kovac's future has not always seemed secure this season but the Bayern boss has his side on track to win a double of Bundesliga and DFB-Pokal titles.
It would be some vindication of the patience shown by Bayern's board when the Croatian coach seemed to be struggling early in the campaign, should they triumph in both competitions.
Lewy the main man again
An ill Lewandowski was only fit enough for the bench in the quarter-finals, but needed to come on as a substitute to score a brace in classic clash with Heidenheim.
And it was the same story as Lewandowski again scored a late penalty to win the tie, although how he failed to clinch the match ball at the death is a mystery.
Klaassen miss costs Werder
Manuel Neuer's deputy Ulreich had little to do prior to the hosts' unexpected comeback, with Klaassen sending a volley flashing over the crossbar at 0-0.
It proved a missed opportunity for Florian Kohfeldt's side and ex-Bayern striker Claudio Pizarro also should have made more of a headed chance in the 91st minute.