A bad-tempered first leg saw Pepe sent off for a high challenge on Dani Alves on the hour and manager Jose Mourinho dismissed shortly afterwards.
Messi gave Barcelona a vital away goal on 76 minutes when he nipped in front of Sergio Ramos and converted a cross from Ibrahim Afellay.
Yet the real magic came with just a couple of minutes of normal time remaining when Messi scored one of the best goals of his career.
The Argentine picked up the ball midway inside the Real Madrid, went past Lassana Diarra, Sergio Ramos, Raul Albiol and Marcelo and then slipped the ball past Iker Casillas.
Check out the highlights below: