Valencia came out strongly in the game, which brought four-match winning streaks to an end for both teams, but were soon hemmed back by Barcelona.
The hosts played their swiftest and most skilful football and Valencia spent much of the first half fending off attacks.
Barcelona were unable to convert their elegant football into goals however and Valencia, returning after the break with a far more aggressive game, were the first to find the net when Stefano Fiore powered in the ball in the 63rd minute.
An already nervous Barcelona were further undermined when Goalkeeper Victor Valdes was sent off 10 minutes later for handling outside the area.
But despite being a man down, Barcelona equalised with a controversial penalty from Ronaldinho in the 79th minute after the Brazilian went down in the area between two defenders.
Canizares dived left as Ronaldinho slotted the ball to his right.
Real also spent much of their match playing catch up, with goals from Michael Owen and Raul putting them back in the game when Racing twice pulled ahead before a last-gasp goal from Zidane in injury time clinched the win.
Creative Israel international Yossi Benayoun, linchpin of the Racing attack, set the pattern when he sent a header soaring over Iker Casillas in the 24th minute.
Michael Owen, relishing an unaccustomed place in the starting line-up, seized his chance to pull the two sides equal with a header after 35 minutes.
But six minutes after the break Javi Guerrero slotted in a pass from Benayoun that found him alone in the area, putting the visitors behind again.
Raul levelled the score 10 minutes later when he knocked a header from Walter Samuel over the line and the game looked to be ending in a draw as both sides struggled to find the net until Zidane sealed the victory.
Real moved to second place on 29 points but were still 10 points behind behind Barcelona, while Valencia moved to thirdalso on 29.