Both sides opted for an attack-minded 4-3-3 formation, although there was no place in the Real line-up for Guti, who had shaken off an injury to be fit for the showdown.
Real went ahead 10 minutes before the break.
Baptista played a fantastic one-two with Ruud van Nistelrooy and when the Dutchman returned the ball to him just inside the area, the Brazilian angled an exquisite half-volley past Valdes and into the top corner to put the visitors ahead.
A minute before the break, Real could then have gone two up.
Barcelona sought to hit back after the break, but Iniesta saw his shot easily gathered by Casillas on 53 minutes.
Substitute Bojan Krkic forced Casillas into fine save on 83 minutes and from the resulting corner, Yaya Toure volleyed just wide on the turn.
Samuel Eto'o then saw his shot deflected just wide by Pepe as the locals pressed for a late equaliser.
But Real hung on through three minutes of added time to claim a vital win and move seven points clear of their bitter rivals after 17 rounds of the Primera Liga.