Messi scored twice with his stunning second strike settling a pulsating clash in the last minute of stoppage time, drawing Barcelona level with Madrid on 75 points at the top of La Liga, although Los Blancos have a game in hand.
The stand-out player in a magnificent match, Messi was a nightmare for Real Madrid whose captain Sergio Ramos was sent off for a hasty two-footed lunge at the Argentine while Casemiro was lucky to avoid red for repeated fouls on the No 10.
Messi eyes 500 as El Clasico looms
Barcelona struggled on the night but Messi led them through the game and was the decisive figure on a dramatic occasion that leaves the Spanish title race wide open.
"[Messi] even makes a difference when he's at home having dinner," joked Barcelona coach Luis Enrique after the game. "He's the best of all time and I have seen a lot of football matches and videos.
"Now people are better prepared and he makes the difference. And this was his 500th goal. Just imagine, his 500th goal coming here, a winner in the 92nd minute at the Santiago Bernabeu. It's very nice for Leo and it's nice for everyone associated with Barca."
Casemiro went into the book for a foul on Messi in the 12th minute as Barcelona's all-time top scorer frequently dropped into midfield to help the team develop moves.
Ronaldo first to 100 Champions League goals
"He allowed us to have superiority in midfield, we wanted him on the ball as often as possible," added Luis Enrique.
Messi was singled out for praise by several teammates after his virtuoso performance helped Barcelona take three points from a game in which they were under pressure for long periods.
Captain Andres Iniesta said: "Leo's greatness doesn't stop surprising us. He is an honour for us and a blessing for the club. We all have to stay with him to have a chance of lifting the title."
Ronaldo first to 100 Champions League goals
Marc-Andre ter Stegen, who made several important saves to keep Real Madrid at bay in the second half, also hailed Messi. "He's the player that makes the difference, a very special player," said the German goalkeeper. "The rest of us made a very big effort and together we earned the victory."
COMMENTS
Comments are moderated and generally will be posted if they are on-topic and not abusive.
For more information, please see our Comments FAQ