Manucho twice put the hosts ahead from corners, but Madrid equalised through first Karim Benzema and then, on the stroke of half-time, Ozil.
The Germany midfielder then curled home a sublime second-half free-kick - his fifth goal in seven games - to secure all three points.
The win lifted Jose Mourinho's third-placed side two points behind Atletico Madrid, who host Deportivo La Coruna on Sunday, and within eight of leaders Barcelona ahead of the Catalan club's trip to Real Betis on Sunday night.
Malaga earlier moved above Betis into fourth spot - for at least 24 hours - as goals from Joaquin, Javier Saviola, Ignacio Camacho and Roque Santa Cruz saw them thrash Granada 4-0 at La Rosaleda.
Elsewhere, Ernesto Valverde's first La Liga match in charge of Valencia ended in a 1-0 win at Osasuna, Roberto Soldado netting the game's only goal 11 minutes into the second half in Pamplona.
The win was Los Che's first on the road in La Liga this term, Mauricio Pellegrino having paid the price for the poor form when he was sacked earlier in the week after the club picked up only two points from their first seven away games.
Finally, Carlos Martinez's stoppage-time header salvaged a 1-1 draw for Real Sociedad as they stretched their unbeaten run to five league games with a point against Getafe at Anoeta.
The game suddenly came to life in the final few minutes when Angel Lafita nodded home from Jaime Gavilan's cross on 87 minutes, but Sociedad responded immediately as Martinez rose highest at the far post to convert Alberto de la Bella's cross.
Atletico and Barcelona are in action on Sunday, with the former hosting Deportivo La Coruna and the latter playing at Real Betis.
Barca could be without forward Lionel Messi after he picked up a knee problem in Wednesday's 0-0 Champions League home draw with Benfica, although the Catalan club will be grateful that the injury is not more serious.
Messi left the field on a cart in the 84th minute after colliding with visiting goalkeeper Artur Moraes and the sight of their star player being taken off the pitch silenced the Barca fans, but there was relief soon after with confirmation that the complaint was no worse than a bruised left knee.
The Argentina international worked in the gym as his Barca team-mates trained outside today, and Messi said he still had a chance of playing at the weekend.
"I feel fine, but I don't know yet if I will be available for Sunday," he said at a promotional event at the Nou Camp on Thursday. "I'll see. I am grateful for all the messages of support I have received."
Messi said he was hurt when he struck Moraes, but then tried to score with a curling shot before falling to the ground and clutching his knee.
"I thought it was the last shot I was going to have for a long time," he said. "So I decided to gamble and hit it."
He added: "The truth is I did not think about anything because all I could feel was the pain. But in a moment I thought the worst. When it was shown it was not a severe injury I was calmer."
The two other matches on Sunday are Levante's home clash with Mallorca and Athletic Bilbao's with Celta Vigo, with Real Zaragoza then making the trip to Rayo Vallecano on Monday night to round things off.
Meanwhile on Friday, Sevilla had striker Alvaro Negredo to thank for rescuing them a point in their 2-2 draw with Espanyol.
Saturday's La Liga Fixtures
Osasuna 0-1 Valencia
Sunday's La Liga Fixtures
Monday's La Liga Fixtures
Rayo Vallecano vs Real Zaragoza
Friday's La Liga Fixtures