Barca were the better side in the first half, but Messi was guilty of two bad misses.
Instead it was Cristiano Ronaldo who opened the scoring, sending a thumping header beyond Victor Valdes soon after the break.
But Barca were behind for barely a minute as Pedro raced clear to equalise, before Messi scored his first Clasico goal in 432 minutes from the spot after Sergio Ramos fouled Andres Iniesta.
Xavi made it 3-1 after superb work by Iniesta, but Angel Di Maria pulled a goal back after a Valdes howler.
Both Jose Mourinho and new Barca coach Tito Vilanova dismissed the Super Cup as meaningless before kick-off, but the memo failed to reach the 95,000 fans that packed the Camp Nou for a Clasico that stands out as one of the best in recent years.
The stadium was rocking as Barca, who left new signing Alex Song out of the squad, took the initiative early on, forcing Madrid to defend uncomfortably deep and restricting them to the occasional counter-attack.
Of course this is often Mourinho’s strategy against Barca – but it worked in the first half as the home side were unable to convert the chances they created.
Given the exceptionally high standards set by Messi in recent seasons, the fact that he went into this Clasico without a goal against Los Blancos in four games, seemed like something of an anomaly.
But he was unable to break that record when he spurned the best chance of the half in the 20th minute. Dani Alves found space on the right and crossed for Messi on the edge of the box, where the forward niftily shifted the ball onto his left foot, but could not keep his shot from rising just over the bar.
Another chance fell to Messi nine minutes later, but again he was off target – dragging his effort wide.
Real Madrid could have gone ahead late in the first half when Karim Benzema was denied by Valdes, but Ronaldo elevated an indifferent personal display with the opener 10 minutes into the second half.
Stealing a yard from Sergio Busquets, Ronaldo’s bullet header beat Valdes at his near post to give Los Blancos an unlikely lead. But it was a lead they could not hold on to.
Virtually straight from kick-off Javier Mascherano’s lofted pass found Pedro, who raced clear of Fabio Coentrao, picked ahead of Marcelo again, and arrowed a low shot into the far corner.
With Real Madrid seemingly abandoning the strict defensive policy adopted in the first half, Barca found holes in their back line – and it was only a matter of time before the Catalan side took the lead.
That chance came when Ramos was caught out by Iniesta’s quick feet and fouled him in the box – and Messi calmly sent Iker Casillas the wrong way from 12 yards.
But Barca were not done. Despite having Pedro off the field and receiving treatment for a hand injury, Iniesta led another Barca counter-attack and spotted the superb run of Xavi. Iniesta’s delightful through ball found his team-mate, who slotted in to make it 3-1.
Barca were denied the chance to make it 4-1 when Casillas pulled off a magnificent save to thwart Messi, whose effort from point-blank range was smothered instinctively by the Spain goalkeeper.
Instead, Madrid broke away and made it 3-2. Failing to clear Adriano’s routine back pass, Valdes opted to take a touch and dribble around Di Maria, who stole possession and turned the ball into the empty net.
It was a farcical end to an enthralling second half in Barcelona that Real Madrid with more than a glimmer of hope of winning their sixth Super Cup when the second leg is played at the Santiago Bernabeu on Wednesday.