Top seed and defending champion Karen Khachanov saved five match points before booking his place in the quarter-finals of the Kremlin Cup in Moscow.
Cheered on by a passionate home crowd, Khachanov recovered from a break down in the final set to beat Philipp Kohlschreiber 3-6 6-3 7-6 (9-7) in almost two and a half hours.
Khachanov saved three match points to force a final-set tie-break, then saved two more to prevent victory for the German, who was celebrating his 36th birthday.
Khachanov told atptour.com: "I can't remember the last time I had a comeback like that.
"I had to fight and try to find my game. I am really happy that finally I can go through here in my hometown of Moscow."
Khachanov, who advanced when Kohlschreiber served his third double-fault, will next face Italy's Andreas Seppi, who fought back to beat Roberto Carballes Baena 5-7 6-1 6-3.
Also in Moscow, fourth seed Dusan Lajovic beat qualifier Lukas Rosol 4-6 7-6 (8-6) 6-3 and seventh seed Adrian Mannarino was a 7-6 (7-4) 6-2 victor over Mikhail Kukushkin.