Novak Djokovic was pushed all the way before finally seeing off Marin Cilic to book his place in the US Open fourth round.
The world number three lost a thrilling first set on a tie-break but was then able to dig deep and edge the next three to progress to the next round, winning 6-7 (7-9) 7-5 6-4 7-6 (7-0).
The Serbian should have made more of early breakthroughs in the last three sets but credit must go to his 19-year-old opponent who was in inspired form at Flushing Meadows.
Djokovic was relieved to have made it through but now believes he can kick on and win his second Grand Slam event.
"I was really trying to stay in the match all the time," he said.
"It is always good in the early stages to have long matches, to hustle and stay on the court a long time. Now I'm motivated to go far.
"I always manage to get through these tough matches. If you are mentally able to play the best tennis in the most important moments you are different than the others.
"I was mentally strong. For me this match is extremely important mentally for me to continue going on."
Djokovic will now face Spain's Tommy Robredo, who had earlier seen off Australian Open finalist Jo-Wilfried Tsonga 7-6 (7-2) 6-2 6-3.