In a rematch of their marathon US Open final of September, which Nadal won in five, the Spaniard looked on the brink of elimination as Medvedev broke his serve twice at the start of the third set.
But at 5-1 down Nadal wriggled out of match point against with a cute drop shot, and hot-headed Russian Medvedev promptly unravelled.
The 23-year-old began sarcastically applauding his coaching team as Nadal hauled back game after game, edging the match ominously towards a tie-break.
Nadal duly got on the board at London’s 02 by wrapping up a dramatic 6-7 (3) 6-3 7-6 (4 ) victory in two hours 44 minutes.
“Today is one of these days that one time out of 1,000 you lose this match, and it happened today,” said Nadal.
“I’m very happy for that, and very sorry for him, honestly, because to lose a match like this is tough, and it’s painful.
“I feel very sorry for Daniil. He’s a good guy, I think, and anyway, he should be very proud about all the things that he’s doing.
“At 5-1, in that moment, what you think is probably in five minutes you are in the locker room, because that’s the more normal thing.
“I played a great point, and then I was able to save that game. Even with 5-2 is so difficult to think about comeback against a player like Daniil.
“But at 5-3, of course I started to believe, because being only one break away, why not? I need to be there. I need to create the moment and I need to put the pressure.
“I created that pressure on him. And then of course he made couple of mistakes, no? But I think I played a good tie-break, too.”
The win means Novak Djokovic has to win the title in order to have any chance of overhauling Nadal at the top of the rankings, making the Serbian’s winner-takes-all clash with Roger Federer all the more mouth-watering.
Nadal, who was well below his best as he slumped in straight sets to Alexander Zverev in his first round-robin match, now faces young Greek star Stefanos Tsitsipas on Friday as he bids to reach the semi-finals.
Crucially, the 33-year-old still seems to be showing no ill-effects following the abdominal problem which forced him to pull out of the Paris Masters earlier this month.
Tsitsipas has already secured his place in the last four after beating defending champion Zverev.
The 21-year-old, who overcame Medvedev in their opening round-robin match, dispatched German Zverev 6-3 6-2.
Tsitsipas admitted he is very taken by those who have gone before him at the O2, although not necessarily the tennis glitterati.
“Taylor Swift, Ed Sheeran, all these celebrities have been here so I’m really glad to have been here. It makes it a very special place,” he said.
Nadal added: “Tsitsipas is a great player with a lot of energy and he’s having an amazing season.
“It will be a tough one but I know I need to win that one.”