The Spaniard is playing his first tournament in six weeks after suffering a stress fracture of a rib.
Less than 24 hours after Real had beaten Manchester City in the semi-finals of the Champions League from a seemingly impossible position, Nadal mounted his own extraordinary recovery to beat Goffin 6-3 5-7 7-6 (9).
Nadal, playing his first tournament in six weeks after suffering a stress fracture of a rib at Indian Wells in March, saved four match points before conquering Goffin on the fourth of his own.
The 35-year-old will play Carlos Alcaraz in the quarter-final, his fellow Spaniard progressing with a 6-4 6-7 (4) 6-3 victory over Great Britain’s Cameron Norrie.
“It was an unforgettable night,” said Nadal – who had been in the stands at the Bernabeu to see Real beat City 3-1 and set up a final date with Liverpool – in his post-match press conference.
“The spirit that the Real Madrid team has is just incredible.
“For me today, in some ways it has been an inspiration in the way I have been fighting all my tennis career.
“I know how hard it is to lose this way so I feel sorry for them (City). But somehow for us, the supporters of Real Madrid, it was an incredible night.”
Nadal had looked on course for a comfortable victory before Goffin, who saved two match points in the second set, won four straight games from 3-5 down.
He saved two of Goffin’s four match points with drop shots, and a third when the Belgian netted a short forehand from an attacking position.
Victory was finally wrapped up in three hours and 10 minutes when Goffin went wide on the Spaniard’s second match point of the tie-break, Nadal advancing to a record-extending 99th ATP Masters 1000 quarter-final.
He said: “I didn’t have a lot of preparation, and we have to see how I’m able to wake up tomorrow after practically two months without any preparation.
“I have to accept that things may not be easy. But I am happy with the victory.
“It gives me an opportunity to play another day. I have a chronic injury which has no treatment.
“That’s part of my life, and that’s the downside of not being able to finish the match earlier. In the short term, I think I am fine, physically speaking.”
Andy Murray had earlier pulled out of his third-round clash with Novak Djokovic because of illness.
It is another unfortunate blow for the former world number one, who defeated Denis Shapovalov on Tuesday for one of the best wins of his comeback and had been looking forward to a first clash with his long-time rival for more than five years.
A post on the tournament’s Twitter feed read: “Unfortunately, Andy Murray is unable to take to the Manolo Santana Stadium due to illness. We wish you a speedy recovery Andy Murray!”
Murray reversed his decision to skip the clay-court season by taking a wild card for Madrid and showed impressive form, defeating Dominic Thiem in the first round and then 14th seed Shapovalov.
Provided he recovers in time, Murray must now decide whether to play in qualifying for next week’s Italian Open, while the French Open is still potentially on the table despite the Scot previously saying he would not play and would instead concentrate on preparing for the grass-court season.
Murray helped set British tennis history in the Spanish capital, joining Dan Evans and Norrie in making it the first time three players have reached at least the third round at the same Masters event on clay.
But none of them made it through with sixth seed Andrey Rublev beating Evans 7-6 (7) 7-5 to set up a last-eight meeting with Stefanos Tsitsipas.
The Greek beat Grigor Dimitrov 6-3 6-4, while Djokovic will meet Hubert Hurkacz next after the Pole overcame Dusan Lajovic 7-5 6-3.
Felix Auger-Aliassime eased past Jannik Sinner 6-1 6-2, and Alexander Zverev was leading Lorenzo Musetti 6-3 1-0 when the Italian qualifier retired.