Real continued to threaten with regularity from set pieces and were rewarded in the 17th minute when Pepe won another header from corner which Valdes pushed out. The ball was loose in the area but as Carles Puyol tried to shepherd it safe Sami Khedira nicked in to stab home.
As the half progressed conditions became slicker as the Catalonian heavens opened and Barca's neat interplay should have provided a goal but Xavi Hernandez pulled his one-on-one effort wide.
The home side maintained their dominance in the possession stats but failed to put a shot on target in the opening period as Madrid went in ahead.
Pep Guardiola's men pressed and pressed and found their equaliser when substitute Alexis Sanchez bundled home at the second attempt after a goalmouth scramble.
The hosts weren't level for long as, moments later, Ozil found Ronaldo and the Portuguese frontman knocked the ball to one side before fizzing past Valdes to set a new La Liga record with his 42nd of the season.
Madrid managed to hold out in the final minutes with Barca's talisman Lionel Messi regularly thwarted by some bullish Real defending.
Three points for Jose Mourinho's men mean they have cemented their position at La Liga's summit with four games of the season remaining.