The 6-4 3-6 6-1 3-6 6-3 win means Federer is now four Grand Slam titles ahead of his Spanish rival, who remains on 14 with Pete Sampras.
"I'd like to congratulate Rafa on an amazing comeback," Federer said at the trophy ceremony.
I would have been happy to lose, too, to be honest, (my) comeback was perfect as it was. Tennis is a tough sport, there are no draws but if there was going to be one I would have been very happy to accept a draw tonight and share it with Rafa.
Federer and Nadal produced one of the finest contests their rivalry has ever seen but it was the Swiss that prevailed, winning after three hours and 38 minutes.
It means Federer has secured his fifth Melbourne crown and a first Grand Slam success since Wimbledon in 2012.
Many predicted a five set classic between the two as has so often been the case in past finals and once more, the match did not disappoint.
Having claimed the third set to move to within one of victory, Federer’s play inspired Nadal to raise his level even further and the Spaniard took the fourth and was 3-1 up in the decider before the Swiss maestro reeled off five games to take the title with a forehand that caught the line.
Highlights: Federer beats Nadal in five-sets to win Australian Open
In winning the final at the age of 35, Federer increased his tally of major titles to an incredible 18 and further cemented his reputation as arguably the greatest player of all time.
For Nadal, defeat will be tough to swallow but the popular Spaniard will once again be one of the favourites when the slam season moves to the clay of his beloved Roland Garros as he seeks to extend his own tally to 15 major titles.
"It was a great match and I think Roger probably deserved it a little more than me," Nadal said.
I played a great quality of tennis during the whole month that I have been playing. That's great news for me. I believe that if I have my body in the right condition, I can have a great year because I feel that I am playing well.
With Novak Djokovic and new world number one Sir Andy Murray raising the standard to new levels, few could have foreseen these two great tennis gladiators gracing a grand slam final again.
If it is to be the last time they grace one of the biggest stages, few will forget the entertainment they provided in this final.