World number one Novak Djokovic kept his hopes of a third successive Australian Open title alive with an extraordinary defeat of Stanislas Wawrinka.
Djokovic came through 1-6 7-5 6-4 6-7 (5/7) 12-10 in five hours and two minutes of absorbing tennis against an opponent who was inspired.
Having withstood an early Wawrinka barrage it seemed the momentum had turned in the Serbian's favour when he claimed sets two and three. But back came Wawrinka to win the fourth in an epic tie-break to take it to a decider which could have gone either way until Djokovic finally made the breakthrough with the match finishing at 1.43am local time.
Djokovic came through some nervous moments, none more so than when he found himself a set and 5-3, 30-0 down with Wawrinka closing in on a commanding lead, but the Swiss got edgy, coughing up three unforced errors which gave Djokovic a route out of trouble and he gleefully accepted.
The momentum was firmly with the Serbian and he broke again for 6-5 before levelling the match on his own serve. To that point it had been all Wawrinka, the 27-year-old blasting winner after winner from all parts of the court with his single-handed backhand particularly venomous.
Djokovic, who has now won 18 consecutive matches here, had no answer. He looked ill-at-ease, not helped by frequently slipping as he struggled with his footwear. Once level, though, he was expected to go on and turn the screw.
The early signs in the third set backed up that theory as he broke immediately, only for Wawrinka to rip up the script and hit back. It remained tight, the two trading lusty blows from the back of the court until the ninth game when Wawrinka again blinked, although credit to Djokovic for raising his level when it really mattered.
Wawrinka would still not go away and he had break-point chances in the second and fourth games of the fourth set with Djokovic clinging on grimly. Cling on he did, though, to take it to a dramatic tie-break.
After two early breaks, serve dominated with few chances on either side of the net until 10-11, when Djokovic's returning game clicked. Wawrinka saved the first two match points - the first with a big serve and the second with an incredibly gutsy backhand winner down the line - but on the third he had no answer as Djokovic ripped a backhand past him at the net.
Djokovic will take on fifth seed Tomas Berdych next, the Czech coming through in straight sets against South African Kevin Anderson.