Messi guided substitute Ibrahim Afellay’s cross through the legs of goalkeeper Iker Casillas to open the scoring in the 76th minute.
With three minutes to play, the elusive Argentina forward brilliantly ghosted past three defenders before clipping the ball past Madrid goalkeeper Iker Casillas for his 52nd goal of the season, and 11th in the Champions League.
Barcelona dominated throughout but only managed to break through after Pepe was red-carded in the 61st at the Santiago Bernabeu Stadium.
Madrid coach Jose Mourinho was sent to the stands for protesting the decision, which left Madrid playing with 10 against Barcelona for the fourth straight game.
Mourinho has seen his team finish with 10 players in his last five matches against Barcelona, counting Inter Milan’s 1-0 defeat at Barcelona in the semifinal return leg last year.
“If I say to (the referee) and to UEFA what I think and feel, my career ends today,” Mourinho said. “One day I hope to get an answer to the question: why?”
It was Barcelona’s first win in three games between the bitter rivals in 12 days after a 1-1 league draw and a 1-0 extra-time Copa del Rey final defeat.
Madrid’s defense in Tuesday’s return leg will be short-handed with Pepe and Sergio Ramos both suspended. Ramos was booked for a foul on Messi in the 53rd.
Mourinho described the second leg in Barcelona as “mission impossible” as he continued to bemoan his side’s treatment by the referee.
“We’ll go there with pride, without Pepe who did nothing, without Ramos who did nothing and the coach who can’t be on the bench,” he said. “If we score a goal they’ll kill us again. It’s a result that is impossible.
“Today showed we have no possibility. And my question is why? I’ll live my whole life with this question but I hope one day to get the answer. Why in a game that was equal did he do what he did? But he won’t answer, he’ll go home because he doesn’t have to answer to anyone.”
Tempers were already running high after both coaches stoked tensions before the match, and substitute Barcelona ‘keeper Jose Manuel Pinto was the first to be sent off for a red card at halftime as the two teams skirmished while leaving the field.
Pepe was then harshly sent off after clashing with Daniel Alves as he lunged for a ball and Mourinho was sent to the stands for sarcastically clapping and showing a thumbs up to the fourth official.
Mourinho took a seat in the first row behind the dugout and began scribbling instructions that were passed to assistant coach Aitor Karanka with his midfield defensive lynchpin out.
Pinto’s sending off left Barcelona without a reserve ‘keeper as the frustration from being unable to exploit 70 percent of the possession seemed to boiled over.
Barcelona dominated possession as expected from the start and Madrid defended always looking for an opportunity to get out on the counterattack, which only materialized when Emmanuel Adebayor came on at the start of the second half.
But Pepe’s expulsion complicated things and the result means Madrid hasn’t beaten Barcelona at the Bernabeu in nearly three years, a run of four games.