Pedro scored the equiliser from Javier Mascherano's pass. Andres Iniesta won a penalty in the 70th minutes after he was brought down by Sergio Ramos, and Messi converted it. Xavi netted the third goal in the 78th minute.
Making good use of goalkeeper Victor Valdes' blunder, Angel Di Maria scored the second goal for Real Madrid as the game came closer to the final whistle.
However, Barcelona team manager Tito Vilanova is not one to ponder over Valdes' error.
"It's a team game. Anyone can make a mistake, I don't give the error any importance," Vilanova told a news conference. "If he played it long all the time, we wouldn't have the combination play we have. We will encourage him to carry on doing it."
Barcelona started their La Liga campaign on Sunday with a huge win over Real Sociedad. Lionel Messi scored two goals and other players like David Villa, Carles Puyol and Pedro scored a goal apiece, winning the match 5-1.
However, Real Madrid didn't have a good start, drawing 1-1 at home with Valencia, who held their nerves and goalkeeper Diego Alves making some great saves.