With Lionel Messi, Luis Suarez and Andres Iniesta all on the bench, Barcelona went behind to the visitors in the 39th minute before Frenchman Jeremy Mathieu equalised in the 46th. Ibai Gomez then scored the winner in the 64th.
Ronaldo, who had been out for two months with a knee injury, scored six minutes into his return as Zinedine Zidane's Real equalled the club's 1960-61 record of 15 successive league victories.
The result left Real Madrid with three wins from three games, while Barcelona are fourth. Sevilla went second on seven points after beating third-placed Las Palmas 2-1.
News that makes sense
Your trusted source for staying up-to-date with the world around you. Get free daily news updates and analysis, straight to your inbox.
(Reporting by Rik Sharma, editing by Alan Baldwin)
