* Midfielder nets 89th-minute free kick
* Real twice come from behind in 2-2 draw
* Dortmund top Group D by one point (Writes through with quotes)
MADRID, Nov 6 (Reuters) - A moment of magic from Mesut Ozil late in the game salvaged a 2-2 draw for Real Madrid at home to Borussia Dortmund on Tuesday and boosted their chances of reaching the Champions League knockout round as Group D winners.
Cristiano Ronaldo usually takes the free kicks for Real but left Ozil to curl a sweet shot into the net off a post in the 89th minute, with Dortmund keeper Roman Weidenfeller slow to react, and put Jose Mourinho's side level for the second time.
Ozil's goal against a side full of his Germany team mates denied Dortmund an impressive double that would have put them in pole position to top the group after they beat Mourinho's expensively assembled side 2-1 in Germany last month.
Marco Reus volleyed the German champions ahead in the 28th minute before Pepe equalised with a header six minutes later and Real's Alvaro Arbeloa poked the ball into his own net on the stroke of halftime at the Bernabeu.
Real enjoyed lots of possession but created few genuine chances and Dortmund's tactic of playing on the break almost earned them another memorable victory.
The draw leaves Dortmund top on eight points after four of their six group matches, with Real second on seven ahead of Ajax Amsterdam (four) and Manchester City (two) following their 2-2 draw in the other match in the section.
Mourinho, who is trying to lead Real to the 10th European crown that has eluded them since 2002, said he did not care whether they finished first or second in the group. They play at City on Nov. 21 and host Ajax on Dec. 4.
"If we finish second it is a problem for the team that finishes first in another group because they don't expect to get someone like us," the Portuguese said at a news conference.
"But I still think we can finish first," he added.
"We played very well in the second half here, aggressive, dynamic. I prefer, and I think the fans prefer, to watch games like these. Other games look more like Europa League ones."
The 5,000 Dortmund fans high up in Real's giant arena were in fine voice long before kickoff, comfortably drowning out the home fans as the hosts controlled possession in the early stages without really threatening.
Marcel Schmelzer and Kevin Grosskreutz tested Iker Casillas after swift attacks before Reus broke the deadlock.
Dortmund's imposing forward Robert Lewandowski nodded a long ball into the midfielder's path and Reus held off Arbeloa before crashing a shot past Casillas on the bounce.
Real levelled when Pepe powered a header into the net from Ozil's cross but Dortmund were back in front moments before halftime when Lewandowski won another header to release Grosskreutz who flicked the ball on for Mario Goetze.
The 20-year-old was initially awarded the goal but replays showed Arbeloa had poked the ball into his own net.
Mourinho, a typically expressive presence on the Real bench, made two changes at the break, hauling off the disappointing Luka Modric and the injured Gonzalo Higuain and replacing them with Michael Essien and Jose Callejon.
His players came out fighting and Callejon sent a low shot narrowly wide in the 49th minute before Weidenfeller did well to block the substitute's close-range effort when he was clean through on the hour.
Ronaldo, top scorer in Europe's elite club competition this season with five goals, had a quiet night although he forced a superb reaction save from Weidenfeller just over 10 minutes from time.
Dortmund looked to be closing in on the win that would have made them only the second German side to claim a victory at the Bernabeu after great rivals Bayern Munich.
However, Ozil, who plays with many of the Dortmund side for Germany, produced a moment of great quality to salvage a point.
"We played well in the second half," Pepe said in an interview with Spanish television.
"They have a great team and everything is still open so we have to keep working," added the Portuguese, whose goal was only his third in Europe's elite club competition.
Dortmund coach Juergen Klopp, known as "Kloppo" by the fans, said he the pride he felt in his team's performance was tinged with sadness that they conceded an equaliser so late on.
"We had direct qualification in our hands," he told a news conference. "But we have two games left. We're pleased with a draw." (Additional reporting by Cillian Shields, writing by Iain Rogers, editing by Ken Ferris)