The defender fired Real Madrid to a second win in five days against the Catalan side, who lost their discipline in the closing stages and had Valdes dismissed after full timeReal Madrid had the measure of Barcelona once again, with a 2-1 victory in Saturday's Liga Clasico at Santiago Bernabeu.
The great rivals squared off just four days after Madrid's 3-1 Copa del Rey win at Camp Nou, but for the vast majority of the game, the tone could not have been any more different, with both sides reluctant to over-exert themselves with Champions League fixtures on the horizon.
With Cristiano Ronaldo looking on from the bench, los Blancos took an early lead after only six minutes when Karim Benzema turned home Alvaro Morata's cross at the far post.
But Barca would soon hit back through Lionel Messi, who finished off a Dani Alves feed to score in his 16th straight Liga game, and equal Alfredo Di Sefano's Clasico record of 18 goals.
The match seemed destined to finish in a draw, but eight minutes from the end, Sergio Ramos rose highest to head home Luka Modric's corner and clinch the points for Madrid.
However, the defender was lucky not to concede a late penalty after a blatant trip on Adriano - an incident that saw Victor Valdes sent off at the final whistle for confronting the referee in an ugly end to the game.
Jose Mourinho's men now move to within a point of second-placed Atletico Madrid, who could cut Barca's lead at the top of the table to single digits should they emerge victorious at Malaga on Sunday.
Xavi was replaced by Thiago in midfield after picking up a hamstring injury while Carles Puyol, perhaps inevitably after his error for Madrid’s second goal midweek, made way for Javier Mascherano in defence.
Mourinho only kept four players who started Tuesday’s match, with Kaka replacing the suspended Angel Di Maria, and Morata chosen to lead the line in the absence of Ronaldo.
And with only six minutes gone, the 20-year-old forward justified his selection by fashioning the opener, taking advantage of Alves’ half-hearted pressure to put in a fantastic cross for Benzema, who was left with a simple tap in at the back post.
But Alves would make amends 12 minutes later. His sublime through pass cut straight through the heart of Madrid and released Messi, who cut onto his left foot ahead of the back-pedalling Ramos and drilled in at the near post.
The on-pitch atmosphere, as expected, was as relaxed as any Clasico in recent years, with the cut-throat intensity of meetings past conspicuously absent.
Messi should have done better on the half-hour mark when played in by David Villa, but with time to pick his spot, he instead shot straight at Diego Lopez.
At the other end of the pitch, Morata went close with an unmarked header from Modric’s cross that agonisingly found the side netting.
In the second half, Raphael Varane had to be at his absolute best to thwart Villa with a sliding tackle at point-blank range, after Messi’s through ball opened up the defence.
With half an hour remaining, Ronaldo was summoned from the bench to replace Kaka, and five minutes after his introduction, the Portuguese made his presence felt with a stinging free-kick that was parried by Victor Valdes.
Morata would go close yet again, but after latching on to Pepe's brilliant pass, he saw his finish thwarted from close range by the alert Valdes.
But with 82 minutes on the clock, Madrid would find the winner. Modric's corner saw the Barca defence hesitate, allowing Ramos just enough time to plant a superb header into the back of the net.
Ronaldo could have put the icing on the game after crashing a 25-yard free kick off the crossbar. Instead, Madrid were the ones left counting their blessings at the end of the game after Ramos' clear trip on Adriano inside the area went uncalled, sparking furious protests from Valdes at the final whistle, earning him two quick yellow cards.