Barcelona came from behind to take a slender 3-2 lead from the first leg of the Spanish Super Cup at the Nou Camp.
Cristiano Ronaldo headed Real into the lead against the run of play 10 minutes into the second half from Mesut Ozil's corner, but Barcelona responded as Pedro showed great poise to slot home a minute later.
The action then raced from end to end and it was Barcelona that forged ahead 20 minutes from time when Lionel Messi scored from the penalty spot after Sergio Ramos had brought down Andres Iniesta.
Then a terrific run from Iniesta freed Xavi to stroke home Barcelona's third goal seven minutes later.
However, the visitors were gifted a way back into the tie five minutes from time when Barcelona goalkeeper Victor Valdes tried to dribble around Angel Di Maria and only succeeded in gifting the Argentinian an open goal.
"I would have preferred 3-1 to 3-2, but we played a good game," Barcelona coach Tito Vilanova said. "The tie (in the second leg) is in still in our favor, so generally we have to be happy."
Real Madrid's Jose Mourinho was not entirely displeased with his team's performance despite the Copa del Rey winner's dominance in possession.
"I didn't like how we played in the first half. A team can change your game plan through its play and Barcelona played well, pressured us a lot and didn't let us get out to attack," Mourinho said. "But we played completely different from the first play of the second half."
The Portuguese coach lashed out at referee Clos Gomez, claiming Pedro was offside on the tying goal.
"I'm not surprised he would say that," Vilanova said.
Barcelona was deserving of the victory but may regret not taking full advantage after dominating for large spells against a Real side that failed to find the cohesion that had seen it go unbeaten in three of its past four trips to the Nou Camp.
Messi had the first real chance of the game when a typically sharp Barcelona passing exchange freed Dani Alves down the right and his cut-back found the Argentinian on the edge of the penalty area, but his left-footed drive flew just off target.
The world player of the year then had an even better opportunity from similar range as he skipped past Alvaro Arbeloa but this time pulled his shot wide of the other upright.
Real was struggling to manage any prolonged possession and was relieved to see referee Gomez wave away appeals for a penalty when Alexis Sanchez tumbled in the box under pressure from Ramos.
However, for all its dominance, Barcelona only had another two long-range efforts on goal as Pedro's drive was tipped over by Iker Casillas before Xavi shot just over from similar range.
And it was the visitors who took the lead 10 minutes into the second period as Ozil's corner was bulleted in by Ronaldo for his fourth goal in his last four away games against Barcelona.
The lead lasted less than a minute as a wonderful ball over the top from Javier Mascherano found Pedro in behind Fabio Coentrao and the Spanish international slotted past Casillas.
The game then became increasingly stretched as both sides tired slightly from playing in the still searing heat, despite the 10:30 p.m. kickoff time, and the visitors' luck with Gomez eventually ran out as Iniesta was brought down inside the area by Ramos and Messi stepped up to thunder home the penalty.
Moments later, Iniesta showed incredible speed to dance past three Real challenges and slip a pass through for Xavi to sidefoot past Casillas.
Messi then had a great chance to all but seal the trophy but he was denied from point-blank range by Casillas, and within seconds the complexion of the tie had completely changed as Valdes' error allowed Di Maria to give Madrid a lifeline heading into the return at the Bernabeu next Wednesday.
Information from Press Association and The Associated Press was used in this report.