Melbourne's marathon man is at it again. Novak Djokovic, who won two successive five-set epics to claim the Australian Open title last year, survived another remarkable test of endurance here yesterday when he beat Stanislas Wawrinka in a five-hour thriller. Wawrinka played the match of his life, only to lose 1-6, 7-5, 6-4, 6-7, 12-10.

Melbourne's marathon man is at it again. Novak Djokovic, who won two successive five-set epics to claim the Australian Open title last year, survived another remarkable test of endurance here yesterday when he beat Stanislas Wawrinka in a five-hour thriller. Wawrinka played the match of his life, only to lose 1-6, 7-5, 6-4, 6-7, 12-10.

It was a superb contest and for Wawrinka it was surely the biggest missed opportunity of his career. The 27-year-old Swiss, who has spent much of his life in Roger Federer's shadow, outplayed Djokovic for long periods, failed to take an opportunity to win the first two sets and was the dominant player for much of the decider, which lasted an hour and 44 minutes.

Djokovic was below his best, but the world No 1 has become the master of crisis management. No player keeps his nerve while on the edge of the precipice quite like the 25-year-old Serb, who won a stunning final point with a superb backhand cross-court pass. Having embraced Wawrinka at the net, he ripped off his shirt and bellowed out a mighty roar in a mixture of relief and celebration.

The match finished at 1.40am, but there were still thousands of spectators present to watch Djokovic keep alive his hopes of becoming the first man in the Open era to win this title three years in a row. His 18th successive victory here earned a quarter-final meeting with Tomas Berdych.

"I feel sorry that one of us had to lose," Djokovic said afterwards. "He definitely deserved to win, but 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 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 was coming up next. So I'm just really full of joy after this match."

Wawrinka, whose bold display earned him the majority of the support from the crowd, said it was "by far the best match I have ever played" but paid tribute to his opponent's resilience. "At the end he was still there," Wawrinka said. "He was playing great tennis. We were both tired, but I really fought like a dog."

The Swiss has one of the game's best backhands – a majestic one-handed stroke struck with great power – but on this occasion his forehand was equally effective. Having lost his previous 10 matches in a row to Djokovic, he decided that attack was his best option. Wawrinka took the game to Djokovic from the start and served with great power and accuracy. At 137mph his quickest serve was 10mph faster than Djokovic's and he did not serve a double-fault until midway through the final set.

Wawrinka won the first set in 25 minutes, after which a lacklustre Djokovic, having looked uneasy on his feet, changed his shoes. It made little difference. Wawrinka went 5-2 up and was within two points of taking a two-sets lead when he served at 5-3 and 30-0, only for Djokovic to hold firm and level the match.

When the Serb took the third set it seemed that the momentum had shifted decisively, but Wawrinka stood his ground and dominated the fourth set tie-break, which he won 7-5. Wawrinka broke in the opening game of the decider and failed to convert two break points in the third game after Djokovic had levelled at 1-1.

His greatest chance, however, came when Djokovic defended four break points when serving at 3-4. He saved the first with an exquisite drop shot before Wawrinka netted a backhand and a forehand on the second and third. On the fourth Wawrinka's crunching return of serve was called long. The Swiss asked the umpire for confirmation and decided not to challenge, only for Hawk-Eye to confirm that the ball had indeed hit the line.

There were no more break points until Wawrinka served at 10-11. The Swiss, who had been cramping, saved the first two match points with a big serve and then a bold backhand winner down the line. The third produced a thrilling rally, both men combining steely defence with some ferocious hitting, and it ended with Djokovic striking a wonderful backhand cross-court pass which Wawrinka was unable to reach.

Wawrinka, who was applauded off the court by Djokovic and was given a standing ovation by the crowd, seemed barely able to climb the steps as he left the arena. "At the end I was really, really close," he said. "For sure I'm really sad. It's a big deception to lose that match, but I think there were more positives than negatives for me."

Djokovic has now featured in – and won – the last three five-set matches in Rod Laver Arena, having beaten Andy Murray after four hours and 50 minutes in last year's semi-finals and defeated Rafael Nadal after five hours and 53 minutes in the final.

"I've been in those situations before," Djokovic said. "I know I can recover. I know I have it in me. I wasn't too worried about the physical part. I was ready for it. I was ready to go the distance and I've done so. Hopefully, I can take that day off tomorrow and recover for the quarter-finals."

David Ferrer, who will replace Nadal as world No 4 next week, beat Kei Nishikori 6-2, 6-1, 6-4. In the quarter-finals he will face his fellow Spaniard, Nicolas Almagro, who went through after Janko Tipsarevic retired hurt in the second set.