Ronaldo came on as a second half substitute with Madrid leading 1-0 after Barcelona's Gerard Pique turned a Marcelo cross into his own net.
Lionel Messi equalised from the penalty spot in the 77th minute after Luis Suarez was fouled in the box by Madrid keeper Keylor Navas.
Ronaldo put Madrid back in front three minutes later when he ran from halfway and produced a stunning strike past Barcelona goalkeeper Marc Andre ter Stegen but he was booked for taking off his shirt to celebrate.
Cristiano Ronaldo celebrates his goal against Barcelona
Cristiano Ronaldo is shown a yellow card by referee Ricardo de Burgos Bengoetxea
And moments later the Portuguese star's night ended in disgrace when he was shown a second yellow card for diving.
The 32-year-old vented his frustration at the referee Ricardo de Burgos Bengoetxea and then pushed him in the back.
Marco Asensio then sealed the game with a 25-yard left-footed effort to cap off a convincing 3-1 win.
Cristiano Ronaldo is shown a red card by referee Ricardo de Burgos Bengoetxea
Cristiano Ronaldo walks off dejected past coach Zinedine Zidane after being sent off Barcelona, who were without Neymar after his transfer to Paris Saint Germain, started with Gerard Deulofeu on the left wing.
Real host Barcelona in Wednesday's second leg.