The bad feeling between the two sides boiled over at the end of the match which saw three players sent off - Marcelo and Mesut Ozil of Real Madrid and Barcelona's David Villa.
Barcelona were far from their best with their players looking rusty and they lacked their usual slick passing, while Real took the game to them.
However, Andres Iniesta put Barca ahead with a deft finish before Cristiano Ronaldo scored his 100th goal in a Real Madrid shirt to equalise.
Messi, though, was the key player as he scored at the end of the first half and again three minutes from the end with French striker Karim Benzema finding the back of the net in between.
Barcelona coach Pep Guardiola was overcome with emotion.
"Words fail me in how to congratulate my players on how they played tonight," he said.
"They are extraordinary and legendary players."
Guardiola only gave new 29million pound signing former Arsenal captain Cesc Fabregas a few minutes of playing time towards the end of the game.
But it was enough time for Marcelo to be dismissed for a late challenge on the Spanish midfielder.
Villa and Ozil were also red carded in the subsequent angry exchanges - the latter being sent off from the substitutes bench as he had gone off earlier in the half - which prompted Guardiola to issue this warning after the match.
"We are going to have to be very careful and calm down the play on the pitch, because this type of match will finish really badly one day," he said.
As in the first game, Real had more possession and posed a greater threat in the opening stages.
Ronaldo had a shot turned behind for a corner as early as the first minute but Barcelona even when not playing well as a team have the players with the individual skills to change the course of the game.
Shortly after Messi just failed to get onto a Pedro cross, the Argentine sliced open the Madrid defence for Iniesta who clipped the ball over the outrushing keeper Iker Casillas.
Real refused to let their heads drop and Angel Di Maria was posing the main danger down the right wing with Ronaldo getting little change from Dani Alves on the other side.
It was the Portuguese who brought Real level though as a deflected Benzema shot appeared to take a final touch off Ronaldo as it wrong footed keeper Victor Valdes.
Real continued to have more of the ball and Ronaldo was inches away from putting them ahead when his drive from the edge of the area was parried by Valdes onto the crossbar.
Ozil then should have done better when his weak strike was comfortably blocked by the Barca keeper.
At the same time whenever Barca got the ball in attack they looked dangerous and Messi restored their lead a minute before the break. Pique back-heeled the ball into his path and Messi dinked the ball over Casillas.
Marcelo who came on for the second half appeared to kick out at Messi and there were angry exchanges between several of the players.
Messi, having only just returned to training after a belated break following the Copa America, was Barca's main danger as he forced Casillas into a low save.
Finally Fabregas was given his bow in front of the home fans with Pedro making way.
Defender Sergio Ramos had a golden opportunity to head Real level before Benzema finally scrambled the ball home in the area.
The game looked to be heading for extra time when Messi pounced to fire home an Adriano cross.
What the stars mean:
★ Poor ★ ★ Promising ★★★ Good ★★★★ Very good ★★★★★ Exceptional