Lewandowski continued his excellent recent form as he scored his 10th goal in as many games, but before he struck in the last minute, the match was still on a knife edge.
"It was a strange game," said the Poland international.
"We desperately wanted to win it, but we were thinking of Madrid. I want to score at least one goal in every game, then I am happy, and if I manage that against Madrid then that would be even better."
The win secured Dortmund's place in the Champions League next season, but they still have some unfinished business in the competition this year.
"We are proud to have qualified for the Champions League again," said defender Marcel Schmelzer on his club's website.
"On Wednesday, we then have the highlight of the current Champions League campaign for us."
Ilkay Gundogan added: "We can now go into the Real game with the wind between our sails.
"It's also important that we're all fit and didn't pick up any injuries."