Roger Federer had to save five match points on his way to a second-round victory over Leonardo Mayer in a match which finished past midnight at the Shanghai Masters.
The third seed was on the back foot from the start as Mayer, of Argentina, broke him in the third game of the match.
The underdog then served for the set at 5-4 but couldn't convert as Federer saved two set points before breaking back in an epic 10th game.
He then broke Mayer again two games later to win the first set 7-5 and complete a run of four straight games.
Mayer wasn't deterred by missing out on the opener and broke Federer right at the start of the second set before this time holding his nerve and winning through 6-3 to force a decider.
The final set was a much tighter affair, with neither man offering up any break points until Federer wobbled when serving to stay in the match at 4-5.
Mayer moved 15-40 ahead and had two match points but couldn't take them. It especially looked like he might come through on the first, but his backhand pass from close to the net agonisingly dropped back on his side after ballooning up off the tape.
Soon the pair were in a tie-break and the entertainment didn't let up.
Mayer took the early initiative and was 5-2 and then 6-4 in front with two more match points. Yet again Federer wouldn't go away and pulled it back to 6-6.
Mayer had another match point at 7-6 but then Federer took over, winning three points on the trot and sealing victory with an inch-perfect lob to the baseline.
Federer, who has never won the tournament, next faces 13th seed Roberto Bautista Agut.