La Liga champions Real struck first when Cristiano Ronaldo headed home in the 55th minute, only for Pedro to break away and level a minute later.
Andres Iniesta was brought down for a penalty, which Messi converted in the 70th minute, and he then went on a mazy run to set up his Spain team mate Xavi for the third in the 78th.
Angel Di Maria pounced on an error from Barca goalkeeper
Victor Valdes to grab a second for Real late on that kept them in touch for Wednesday's return leg at the Bernabeu.
"In the end the result is tighter than we would have wanted considering the chances we created," Pedro told Spanish television. "We are pleased and now we have to play a good game there if we want to win the title."
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 but, despite the close attentions of the Real's players, 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 match burst into life when Ronaldo powered in a header from Mesut Ozil's corner. But almost from the restart Javier Mascherano played a ball long ball over the top for Pedro.
The Spain forward's first touch was magnificent and he fired past Casillas, though replays suggested he had started in an offside position.
The game opened up and Sergio Ramos brought down Iniesta for penalty, and Messi netted from the spot.
Iniesta dribbled past three players and threaded a ball through for Xavi to score and soon after Casillas denied Messi a fourth for the hosts.
Substitute Di Maria chased down Valdes at the end as he controlled the ball in the area, and stole it off him to grab a lifeline for Mourinho's men.
(For more sports news and updates, follow Ahram Online Sports on Twitter at @AO Sports and on Facebook at AhramOnlineSports)