If Novak Djokovic were an author, he would be writing epics.

As the world's best tennis player, he simply revels in them. Last night, for the umpteenth time over the past few years, the world No.1 found himself in a hole, flirted with disaster but somehow battled back for victory. It is the absolute mark of a champion, and anyone who wants to wrest the Australian Open title from his grasp is going to have to break his spirit. It may not be possible.

His 1-6, 7-5, 6-4, 6-7, 12-10 victory over a gallant, mostly brilliant, Stanislas Wawrinka of Switzerland yesterday took top seed Djokovic into his 19th straight grand slam quarter-final and, more importantly, kept intact his hopes of a third straight Australian Open crown, just.

Djokovic said the match was as good as any in his career, grand words when you think he needed almost five hours to beat Andy Murray in the semi-finals here last year and almost six to beat Rafael Nadal in the final.

But after five hours, two minutes of stunning tennis, with Wawrinka playing out of his skin, Djokovic somehow came out on top, thanks to his belief, his utter, incredible belief that he can get himself out of trouble when he needs to.

"Even though when I was 6-1, 5-2 down, I believed that I can come back if I am two sets down," said Djokovic, who gratefully accepted a tray of food from tournament director Craig Tiley soon after the match, which finished at 1.45am.

"I've been in those situations before. I was just outplayed by my opponent. He was better on the court for the first hour and a half, no question about it. In these circumstances, when you're not playing the way you want to play, you just try to fight and hope for the best."

Wawrinka's talent has never been in question but he has lived in Roger Federer's shadow throughout his career and, having only ever made two grand slam quarter-finals, including one here two years ago, few thought him capable of matching Djokovic.

In the first set, Wawrinka was flawless. His serve was strong, he targeted the Djokovic forehand and his own backhand, always a thing of beauty, was perfectly in sync. When he took the set and led 5-2 in the second, Djokovic was as stunned as the crowd.

But as Wawrinka briefly faltered, Djokovic snapped into life, winning five straight games to level the match, before coming out on top in a tight third set. That might have been the moment for Wawrinka to fade away but he kept on attacking and never allowed the Serb to relax, playing a brilliant tiebreak to level the match at two sets apiece.

Wawrinka then broke in the first game of the decider only for Djokovic to break straight back.

If anything, Djokovic was hanging on and the Swiss looked the stronger, despite a touch of cramp creeping in.

His big chance came at 4-4 when a woeful volley from Djokovic gave him 15-40. Djokovic saved the first break point with an audacious drop shot, before Wawrinka made a rare error on the backhand side. Two more break chances came and went, including one when Wawrinka decided not to challenge a call on his return that replays showed landed on the baseline. Djokovic held and, from then on, Wawrinka was always playing catch-up.

He did it brilliantly for six more service games but at 11-10 to Djokovic, the Serb earned a match point with a backhand pass that clipped the net. Wawrinka saved it with a service winner and then, after Djokovic earned another, hit a stunning backhand winner down the line.

But a netted backhand gave the top seed a third chance and after another sensational rally Djokovic rolled a beautiful cross-court backhand pass that left Wawrinka stranded.

Djokovic will rest before taking on Czech Tomas Berdych in the quarter-final tomorrow night and he said he was confident he will be fully fit.

"I know I can recover, I know I have it in me," he said. "I wasn't too worried about the physical part. I was ready to go the distance and I've done so. Hopefully I can take that day off and recover for the quarters.

"I'm just thrilled to be able to fight once again up to the last moment. The fact is that I haven't played nearly my best and I didn't feel well on the court in terms of rhythm and ball striking.

"But all the credit to him, he made me run all over the court. He never gave me the same ball. He was aggressive from both sides. I didn't know what's coming up next. So I'm just really full of joy after this match."

Wawrinka fought back a few tears as he tried to understand how he had not won. "I think it's by far the best match I ever played, especially in five sets against the No.1 player," the Swiss said. "At the end I was really, really close. For sure I'm really sad. But I think there is more positive than negative. Even if I was up two sets to love, I don't think the result would have changed because everybody knows how he fights every match. I had opportunities in the fourth set to break him. At 4-4 I had some chances to take the match. But he was just better."

Fourth seed David Ferrer beat Kei Nishikori of Japan in straight sets to set up a meeting with Nicolas Almagro of Spain, who was leading Serb Janko Tipsarevic by a set and 5-1 when the Serb retired with a foot injury.