Barca fight back to take control of Super Cup
Pedro, Lionel Messi from the penalty spot, and Xavi scored for holders Barca as they stormed back after Cristiano Ronaldo had headed the opener in the 55th minute at the Nou Camp.
With five minutes to go, however, Angel di Maria pressured Valdes in his area as he controlled a backpass, stole the ball off him and scored while Barca's defenders looked on aghast.
Real's late goal took the shine off Tito Vilanova's first 'Clasico' as coach since he stepped up from assistant to replace Pep Guardiola, but he was sanguine about the error.
"It's a team game. Anyone can make a mistake, I don't give the error any importance," Vilanova told a news conference.
Valdes is the starting point for much of Barca's possession play from the back and is well known for his accurate distribution with his feet.
"If he played it long all the time we wouldn't have the combination play we have," Vilanova added. "We will encourage him to carry on doing it."
The game had a muted opening, following the pattern of recent clashes, with Barca dominating possession and Real looking to steal the ball and break quickly.
Niggly fouls interrupted the flow and it was Messi who looked most likely to break the deadlock.
He fired just wide of the post twice but it was Pedro who forced the first save with a fierce shot that was tipped over by Iker Casillas in the 32nd.
The visitors came out stronger in the second half and the match burst into life when Ronaldo powered in a header from Mesut Ozil's corner, and celebrated by calling for the Nou Camp to go quiet.
Almost from the restart Javier Mascherano played a ball over the top for Pedro. The Spain forward's first touch was magnificent as he sped past Fabio Coentrao and fired in the equaliser.
Television replays suggested Pedro had started in an offside position, which Real coach Jose Mourinho was quick to pounce on.
"I didn't like Barca's first goal, it was an error by the touch judge," he said.
The game opened up and Sergio Ramos brought down Andres Iniesta for a penalty in the 70th, and Messi netted from the spot, his 14th goal against Barca's arch-rivals.
Iniesta dribbled past three players and threaded a ball through for Xavi to score the third in the 78th and soon after Casillas denied Messi a fourth for the hosts.
That proved to be a decisive moment as the play swung down the other end of the pitch, and Di Maria poached Real's second.
"In the end the result is tighter than we would have wanted considering the chances we created," Pedro told Spanish television.
"Now we have to play a good game there if we want to win the title."
The second leg is at the Bernabeu on Wednesday.