Marco Reus had deservedly put the German champions in front on 28 minutes with a spectacular volley from Robert Lewandowski's knockdown, but Pepe levelled for the hosts six minutes later with a bullet header from Ozil's cross.
The visitors went back in front seconds before the break as Mario Gotze's chip over Iker Casillas found the net via a deflection off Alvaro Arbeloa, but Madrid were much improved after half-time and finally got level thanks to Ozil's perfectly placed free-kick.
Dortmund had failed to win in their previous six European games away from home but started well, Marcel Schmelzer - who had struck the winner when the sides met in Germany a fortnight ago - was first to threaten on nine minutes, but after Casillas had parried his initial effort Lewandowski wastefully volleyed over the rebound.
Real's first notable chance inevitably fell to Cristiano Ronaldo, but his mistimed header went wide and, with Dortmund consistently causing problems in behind the Real full-backs, it was no surprise when the opening goal arrived from that area as Neven Subotic's long ball was headed down by Lewandowski and brilliantly volleyed high past Casillas by Reus.
The lead only lasted six minutes though as Dortmund failed to properly clear a corner from the left and Ozil's cross was powered home at the far post by Pepe.
Raphael Varane then had to make a fine saving tackle to prevent Reus breaking clear on goal again, but Dortmund retook the lead right on half-time; a long ball to Lewandowski caused problems as Kevin Grosskreutz raced onto his flick on and then lobbed the ball into Gotze, who calmly lifted it home over Casillas via a deflection off Arbeloa.
Real boss Jose Mourinho made two changes at half-time as Gonzalo Higuain, who had been struggling with a hamstring injury, and Luka Modric were replaced by Jose Maria Callejon and Michael Essien. Callejon almost made an immediate impact as he swept the ball home from Ozil's pass but the goal was ruled out for offside.
Roman Weidenfeller made a remarkable save with his legs to keep his side ahead as Ronaldo turned Angel Di Maria's low cross towards goal from six yards 12 minutes from time, and Dortmund were then rescued by a goal-line clearance from Grosskreutz as Callejon squeezed another effort on target inside a packed penalty box.
However, the pressure finally told as Ozil's brilliant free-kick from 20 yards crept inside Weidenfeller's left-hand post a minute from time.