Gerard Pique's towering header put the hosts in front on the night they honoured legendary former player and coach Johan Cruyff.
Yet, Karim Benzema quickly levelled before Ronaldo fired home five minutes from time after Madrid captain Sergio Ramos had seen the 21st red card of his career.
Victory reduces Barca's lead over third-placed Madrid to seven points with seven games remaining, but Atletico Madrid closed the gap on the leaders to six points with a 5-1 thrashing of Real Betis earlier on Saturday.
There was an emotive homage to Cruyff before kick-off with over 90,000 fans holding up a display reading "Thank you Johan" alongside a Barca jersey with the number 14 the Dutch great adorned during his playing career.
Once the action got underway, Barca started by far the better and only an incredible miss by Luis Suarez let Madrid off the hook on 10 minutes.
Neymar unselfishly squared for his Uruguayan strike partner, but Suarez failed to make any connection from his low cross with the goal at his mercy.
Keylor Navas was then forced to make a smart save from Ivan Rakitic as Madrid struggled to contain wave upon wave of Barca attack.
The hosts were enraged midway through the half when Lionel Messi looked to have been brought down by Ramos right on the edge of the area, but referee Alejandro Jose Hernandez waived play on with Ramos already having been booked.
Madrid grew into the game as the first-half progressed and finally threatened the Barca goal when Ronaldo's shot was beaten away by Claudio Bravo before Gareth Bale blazed a volley over from a narrow angle.
Barca started on the front foot again after the break and Navas made a brilliant save to prevent Messi's cheeky chipped effort floating in at the far post.
Yet, that save only momentarily denied Barca as Pique rose highest to power home Rakitic's corner on 56 minutes.
The lead lasted just six minutes, though, as Benzema swivelled by blast home Toni Kroos's deflected cross into the bottom corner.
Bale had the chance to turn the game on its head, but his tame effort on his favoured left foot was easily held by Bravo as Madrid again threatened on the counter-attack.
The Welshman did have the ball in the net nine minutes from time, but was incredibly unfortunate to be penalised for a push on Jordi Alba as he headed in.
Ronaldo then fired against the bar and Bravo saved a one-on-one with Bale as Madrid's pace on the break began to tear a tired-looking Barca apart.
The visitors' hopes of a famous win looked to have gone when Ramos was finally given his marching orders for a second booking after chopping down Suarez seven minutes from time.
Yet, just two minutes later Ronaldo struck the winner as he controlled Bale's cross to the far post before slotting under Bravo.
COMMENTS
Comments are moderated and generally will be posted if they are on-topic and not abusive.
For more information, please see our Comments FAQ