Messi netted from the penalty spot after Luis Suarez's opener and then teed up Aleix Vidal for Barca's third in stoppage time.
Madrid had a number of chances to go in front in the first half, with Marc-Andre Ter Stegen saving one Cristiano Ronaldo effort with his feet and Karim Benzema glancing a header against the outside of the post.
The Catalan giants are now sitting pretty atop of La Liga, a full 14 points clear of Real.
"This hurts more than any other game, but we can use it to reflect to try to keep improving, but this defeat doesn't tarnish our 2017, which has been a historic year".
"In Barcelona they will say I need to go to prison with Puigdemont", Ramos said. The fact that Dani Carvajal was sent off is immaterial - it did not change the game, because Barca were already well on top by then and the right-back staying on the field wouldn't have made much difference. Suarez believes that Valencia and Atletico Madrid will be their rivals for the title.
Despite the current situation, Barcelona coach Ernesto Valverde and his players aren't excluding a Madrid comeback.
"Of course not, the first round of fixtures hasn't even finished".
"Our history and our badge oblige us to fight until the end", Ramos said.
"We're only focusing on our games, our points and our sensations".
It was also played in the backdrop of a political crisis in the country, coming two days after elections in Catalonia in which separatist parties won a majority. The volume in the packed Bernabeu was cranked up when Ronaldo headed a corner in off the crossbar in under two minutes but the offside flag halted the premature celebrations.
The French coach surprised many by picking Mateo Kovacic in place of Isco as he sought to strengthen the midfield, but after a strong first half display Madrid were repeatedly ripped apart on the counterattack by Barca, with Kovacic losing Ivan Rakitic in the build up to Barca's opener.