Sevilla went 2-0 up at the Ramon Sanchez-Pizjuan Stadium thanks to quick-fire goals from Ivan Rakitic and Erik Lamela.
But Real came roaring back in the second half to win all three points.
Goals from Rodrygo and Nacho meant the score was level going into stoppage-time.
Karim Benzema then netted in the 92nd minute to complete an incredible comeback.
The comeback may not have been possible, however, had Eduardo Camavinga been shown a second yellow card in the first-half.
Camavinga was booked after taking out Jesús Manuel Corona in the 31st minute.
Nine minutes later, he was extremely unfortunate not to be given his marching orders.
What’s your take on this one?— SpelTorsten.se (@SpelTorsten) April 18, 2022
Camavinga avoided a second yellow card for this challenge on Martial late in the first half.
Instead Martial receive a yellow for his reaction. With VAR and everything this shouldn’t be possible. Sevilla – Real Madrid #LaLigaSantander pic.twitter.com/8fOnGP4aBZ
Anthony Martial broke forward with the ball and Camavinga sent him to the ground with a cynical challenge.
The referee, though, deemed that Camavinga had got the ball and did not give a foul.
Replays showed that the youngster was nowhere near getting the ball.
Martial was absolutely fuming. He went to the ground in pain and was his frustration was plain to see.
The on-loan Manchester United forward, ironically, was the player who was given a yellow card as he was punished for his reaction to the foul.
The 26-year-old could not continue and had to be substituted off.
Should the referee have blown for a foul, Camavinga would almost certainly have been sent off and any hope of a comeback would have been all but extinguished.
But he was allowed to stay on the pitch and Real went on to clinch a vital three points.
Real are now 15 points clear of Barcelona at the top of La Liga.
The Catalan giants have two games-in-hand but need a miracle if they are to catch Carlo Ancelotti’s side.
The ultimate Ronaldo Nazario quiz: How much do you know about the Brazilian legend?