Roger Federer won his 18th Grand Slam title and first for five years with a thrilling five-set victory over Rafael Nadal in the Australian Open final.

The 35-year-old Swiss won 6-4 3-6 6-1 3-6 6-3 to claim his fifth Melbourne title and extend his lead at the top of the all-time men's major winners' list.

Nadal, 30, remains tied in second with Pete Sampras on 14 Grand Slams following his first final since 2014.

Federer's previous major title came at Wimbledon in 2012.

"I've been coming here for almost 20 years now," he said. "I've always enjoyed it and now my family does too.

"Thanks again for everything, to everybody. I hope to see you next year. If not, this was a wonderful run here and I can't be more happy to win."

Men's all-time Grand Slam singles titles leaders 18 (2003-present) - Roger Federer (Swi) 12 (1961-1967) - Roy Emerson (Aus) 14 (2005-present) - Rafael Nadal (Spa) 11 (1974-1981) - Bjorn Borg (Swe) 14 (1990-2002) - Pete Sampras (US) 11 (1960-1969) - Rod Laver (Aus) 12 (2008-present) - Novak Djokovic (Ser) 10 (1920-1930) - Bill Tilden (US)

Federer's achievement in ending his drought is all the more remarkable given this was his first tournament since Wimbledon last July, after which he took the second half of the season off to recover from a knee injury.

He becomes the first man in history to win five or more titles at three different Grand Slam events - five Australian Opens, five US Opens and seven Wimbledons.

Nadal was also on the way back from injuries that curtailed his 2016 season, but the Spaniard could not improve his winning record against Federer - the Swiss has now won 12 of their 35 matches and three of nine major finals.

"I worked very hard to get where I am," said Nadal. "I fight a lot, probably Roger deserved it a little bit more than me.

"I'm just going to keep trying. I feel I am back at a very high level."

Final lives up to the hype

Federer beat Nadal in a Grand Slam final for the first time in 10 years

The return of one of the great tennis rivalries to the Grand Slam final stage led to huge anticipation, and it lived up to the billing over three hours and 37 minutes.

A match of wild momentum swings ended with a purple patch from Federer that saw him win the last five games, and clinch the title thanks to confirmation from a Hawk-Eye challenge.

Federer leapt in the air in celebration and, after consoling close friend Nadal, broke down in tears as his wife Mirka and his team celebrated in the stands.

"Tennis is a tough sport," said Federer. "There are no draws. If there were I would have been happy to accept one and share it with Rafa.

"Everybody says they work very hard - I do the same - but I try not to shout about it. I'd like to thank my team. It's been a different last six months. I didn't think I'd make it but here I am."

The injury lay-offs meant Federer was seeded 17th in Melbourne and Nadal ninth, but the Swiss will now return to the world's top 10 and Nadal will move up to sixth.

Federer finishes with a flourish

There were moments of genius from both players - a stunning forehand angled winner from Nadal as he dominated the fourth set, a breathtaking 26-stroke rally in the fifth that ended with a crushing Federer forehand - but in the end the attacking instincts of Federer held sway.

He dropped just four points on serve in the first set, breaking serve after a brilliant drive volley in game seven, only for Nadal to race 4-0 clear in the second.

Federer recovered one of the breaks but it was not enough as Nadal served out to love to level the match, and then heaped on the pressure early in the third.

With the momentum slipping away, Federer came up with three aces on break points to nudge ahead in the first game - and it proved to be a decisive moment.

Federer needed medical treatment to his thigh in the final set

A magical half-volley forehand helped Federer get the break in the next game and he rolled through the set for the loss of just one game.

Neither had been able to produce their very best consistently and it was Federer's turn to leak forehand errors as he fell behind in the fourth set, and Nadal appeared the stronger as they headed into a decider.

Federer needed an off-court medical time-out, just as he had before the fifth set of his semi-final against Stan Wawrinka, and he had treatment to his thigh on the changeover as he fell 3-1 behind.

Despite his physical issues, Federer continued to press on the Nadal serve, earning break points in each game until he finally converted a sixth to level at 3-3.

The Rod Laver Arena crowd roared as the Swiss swept through a service game and then broke again in a dramatic game, winning a 26-stroke rally that will rank among the best ever.

Closing out a Grand Slam final was never going to be easy after five years, and Federer had to recover from 15-40 before firing a forehand onto the line and waiting for Hawk-Eye to confirm it was a historic winner.

Federer v Nadal in Grand Slam finals

2006: French Open - Nadal won 1-6 6-1 6-4 7-6 (7-4)

2006: Wimbledon - Federer won 6-0 7-6 (7-5) 6-7 (2-7) 6-3

2007: French Open - Nadal won 6-3 4-6 6-3 6-4

2007: Wimbledon - Federer won 7-6 (9-7) 4-6 7-6 (7-3) 2-6 6-2

2008: French Open - Nadal won 6-1 6-3 6-0

2008: Wimbledon - Nadal won 6-4 6-4 6-7 (5-7) 6-7 (8-10) 9-7

2009: Australian Open - Nadal won 7-5 3-6 7-6 (7-3) 3-6 6-2

2011: French Open - Nadal won 7-5 7-6 (7-3) 5-7 6-1

2017: Australian Open - Federer won 6-4 3-6 6-1 3-6 6-3