Andre Agassi needed all his experience to see off Sweden's Joachim Johansson and stay on course for a fifth title at the Australian Open.
Agassi faced a barrage of big serves but stood firm and finally came through 6-7 (4/7) 7-6 (7/5) 7-6 (7/3) 6-4.
Johansson sent down 51 aces, a new world record, and hit 96 winners but still came off second best.
Agassi, the eighth seed, was broken early in the fourth set but bounced back with a double break to win.
The American's delight at setting up a quarter-final against Roger Federer was a far cry from the look of disbelief that fell over his face at the end of the first set.
Agassi was aghast to have lost it despite having made no unforced errors.
"It was a tough day," Agassi said. "Joachim was hitting the ball so big. What can you do but sort of react?
"I was anxious the whole time. I had to stay focused and disciplined, give myself a look and hope I can convert on the few chances I do get.
"I'm excited," he added when asked about the match against Federer. "This is what I prepare for, to play the best in the biggest of situations.
"Roger offers me the opportunity to push myself more than I've been pushed in a long time. That's a great feeling.
"It's what makes sport so great. You can't phone in the result. You got to show up and you got to tee 'em up and you got to find a way to get it done."
Johansson, who came into the match carrying a slight leg injury, lost his opening service game but soon broke back.
He then threatened to overwhelm the 34-year-old Agassi with the power of his serve, 14 aces helping him clinch the first set in a tie-break.
But the 22-year-old relied on much more than brute strength as he mixed stunning groundstrokes down either flank, deft drop shots and heavy slices into his repertoire.
He showed no sign of letting up in the second set, during which both players saved break points, but Agassi levelled in the tie-break.
The third set also went to a tie-break which Agassi again won to take a decisive advantage.
After 31 successive games with serve, Johansson gave himself a glimmer of hope when he broke Agassi in the second game of the fourth set.
But after saving three break points in his subsequent service game, the hard-hitting 11th seed failed to hold from deuce, and after he was broken again the game was up.