Barca, not having the best of times in the la liga this season, scored just after the halftime break after Luis Suarez headed in a Neymar cross, but left their home supporters disappointed as Ramos rose above everyone to nod in the ball at the 90th minute after a Luka Modric free kick.
It was all joy for Zinedine Zidane's men including Cristiano Ronaldo who was frustrated through out the night as he missed so many chances.
Barcelona started with Ter Stegen, Alba, Pique, Mascherano, Sergi Roberto; Gomes, Rakitic, Busquets; Suarez, Messi and Neymar and had to introduce Iniesta in the second half while Real Madrid started with Keylor Navas, Carvajal, Marcelo, Varane, Ramos; Modric, Kovacic, Isco, Lucas, Cristiano Ronaldo and Karim Benzema.
Real Madrid dominated proceedings in the first half as Neymar and Suarez were very poor in the first half, combining poorly, but in the second half, they combined to give Barca the lead while Iniesta (back from injury) was introduced in the second half- to lead Barca's ball possession based mantra in the center of the park.
Barca knew they were ahead and started playing possession football- Real Madrid's coach Zinedine Zidane, knowing he had to win the midfield battle, responded by putting on Casemiro for Isco.
Messi missed, Ramos blocked, Neymar missed, and Barca only had themselves to blame as Ramos slotted the ball into the net, after a Modric free kick that resulted from Arda Turan's foul on Marcelo.
Madrid now lead Barca with six points at the top of the La liga table.