Jose Mourinho's men brought Barca's 11-game winning streak in La Liga to a shuddering halt and effectively clinched the title with four games remaining when silencing Camp Nou with a fine performance against a disappointing Barca side.
Sami Khedira put Madrid in front after 17 minutes when turning the ball home from close range following a corner and although Alexis Sanchez equalised just seconds after his arrival as a substitute, Madrid responded quickly through a 42nd league goal of the season for Cristiano Ronaldo after 73 minutes.
Madrid enjoyed only their second win in 11 games against Barcelona under Mourinho, in the process finally overcoming the inferiority complex that has dogged them in encounters against their fierce rivals and surely ensuring they will end the season by taking the Liga title away from the Catalans.
Despite some painful memories of the same fixture last season, Mourinho fielded the identical front six that were subjected to a savage 5-0 defeat in November 2010 with Xabi Alonso and Khedira forming a two-man screen to combat Barcelona's attack. However, the contrast in performance could hardly have been more marked.
Meanwhile Barca, who fell to a 1-0 defeat at Chelsea in the Champions League in midweek while Madrid succumbed to a 2-1 defeat at Bayern Munich, made two changes with Thiago and Cristian Tello, who looked a touch lost when making only his fourth senior start, coming in for Cesc Fabregas and Sanchez.
The home side, aiming to extend their unbeaten run against Madrid to a record eight games, opted for a three-man defence but could not find room for Gerard Pique who had to be content with a place on the bench. Adriano and Javier Mascherano could not offer an adequate aerial presence though and Madrid duly sought to exploit any opportunities from set-pieces in a confident start at Camp Nou.
As early as the fifth minute a corner from Mesut Ozil was met by Ronaldo and though his header took a deflection off the shoulder of Carles Puyol, it still required a save on the stretch from Victor Valdes to turn it over the bar. Pepe then headed over from the subsequent corner as Barca were exposed in the air once again.
Though only a smart save from Iker Casillas prevented Dani Alves from rounding the Spain keeper following a slack pass from Pepe, Barca were struggling to impose their usual fluid style against a robust yet dynamic Madrid side. Xavi, Andres Iniesta and Lionel Messi sought to monopolise possession yet chances only arrived sporadically.
By contrast, Madrid unsettled Barca and on 17 minutes Mourinho's side took the lead from a set-piece. Pepe dwarfed Adriano to meet a corner from the right and Valdes, out of position having initially come off his line for the ball, threw out a hand to stop the header. Puyol was ostensibly on hand to clear yet got the ball caught under his feet, allowing Khedira to stick his leg in and poke it over the line.
The goal was Madrid's 108th in La Liga this season, breaking the record set by John Toshack's side in the 1989-90 campaign, and Madrid were content to reign in their attacking intent as a result, with Barca exercising an even greater grip on possession as they pursued an equaliser.
Though Tello and Thiago, the two La Masia graduates players brought into the side, drilled efforts wide of the post from range, the finest chance of the half fell to Xavi on 27 minutes. Messi embarked on a lovely run before opening up the visiting defence with a superb reverse pass and Xavi spurned the glorious opening when directing his effort just wide of the far post via a faint touch from Casillas.
Having struggled to attain their usual standards, it was something of a surprise to see the same Barca XI emerge for the second half, particularly with Pedro and Sanchez looking ripe to replace Tello.
The young forward, making his first start in La Liga, continued to frustrate in the early stages of the second half. After lashing one shot off target following a sumptuous pass from Iniesta, he then wasted a even better ball from Thiago, who carved open the Madrid defence to find his team-mate. Tello was in a fine position to convert but got his foot under the ball and lifted it high over the bar.
Barca were readying Sanchez on the touchline and Tello appeared vulnerable, yet it was Xavi who was removed just seconds after he drove a fearsome shot narrowly wide of the post following a neat square pass from Thiago.
The change brought immediate reward as Sanchez scored within a minute of his introduction. Iniesta released Tello with a glorious flick on the edge of the box but after Casillas repelled his low effort and Adriano then saw his follow-up deflected into the path of Sanchez, the forward somehow bundled the ball home at the second attempt for the scrappiest of equalisers.
Momentum appeared to be with the reigning champions yet Madrid responded within three minutes with the kind of devastating counter-attack that has been their forte under Mourinho. The ball was worked to Ozil on the right flank and he played in Ronaldo with a brilliantly-weighted pass that allowed the forward to take a touch and draw Valdes before finishing past the Barca keeper in style.
Madrid closed out the game in accomplished fashion, ending Barca's 54-game unbeaten home record in all competitions and all but ensuring that the title will be returning to the capital for the first time since 2008.