Federer, 35, won a classic encounter 6-4, 3-6, 6-1, 3-6, 6-3 to become the oldest major-winner in 45 years and move four titles clear of Nadal and Pete Sampras on the all-time list.
The veteran Swiss jumped for joy and cried tears of happiness as he sealed the win on his second championship point, ending a five-year wait for a big victory after Wimbledon in 2012.
Neither Federer nor Nadal, 30, was expected to reach the final but both players grabbed their chance after the early demise of top seeds Andy Murray and Novak Djokovic.
And it was a final for the ages as momentum shifted from one side to the other before Federer finally seized control in the deciding set.
"That is a milestone in my career, they are always epic matches against Rafa," said Federer, adding: "Rafa has caused me the most problems in my career."
For Federer, it sealed an astonishing comeback from six months out with injury. His fifth Australian title came seven long years after his last, against Murray in 2010.
"Tennis is a tough sport, there's 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, really," Federer said.
"Keep playing please, Rafa. Tennis needs you."
Federer becomes the oldest major champion since Ken Rosewall won the Australian Open in 1972 at the age of 37.
His ranking has dipped to 17 after a knee problem ended last season following Wimbledon, but he will now rise to 10 when the new rankings are released this week.
It was the 35th meeting between the two long-time rivals with Nadal now leading 23-12 and 6-3 in major finals, including his five-set win over Federer in the 2009 Australian final.
The 35-year-old Swiss admitted his return to Melbourne wasn't guaranteed, telling the Rod Laver Arena crowd: "I hope to see you next year, but if not, then it was a wonderful year here and I couldn't be happier tonight."
Federer has been rebutting suggestions of retirement for several years, but he said he was now aware injuries could force him off the scene.
"This is all about, you know, knowing that I have only so much tennis left in me," he told reporters, when asked about the comment in his acceptance speech.
"If I do get injured, you know, maybe if I miss next year, who knows what happens... You never know when your next Grand Slam is going to be, if ever.
"You never know if you're going to have an opportunity at this stage."
Federer added: "Look, I've had a tough year last year. Three five-setters are not going to help. I just meant it the way I meant it.
"There wasn't something planned behind it, that this is my last Australian Open. I hope can I come back, of course. That's my hope right now."
Federer slammed comments that he had engaged in "legal cheating" by taking a medical timeout at a crucial stage of the match.
The Swiss champ went off for treatment just before the deciding fifth set, after Nadal had levelled the match at two sets all.
Australia's former Wimbledon champion Pat Cash criticized Federer, who also had a timeout before the fifth set of his semifinal with Stan Wawrinka.
"You can't just stop a marathon if you're tired... I can't stress how bad this has been supervised or looked at by the medical team here in the whole tour," Cash said on BBC radio.
"It's wrong, wrong and wrong. It's cheating and it's being allowed. It's legal cheating, but it's still not right."
But Federer defended his right to receive treatment, saying he had been feeling pain in his upper right thigh for much of the tournament.
"I also think we shouldn't be using these rules or abusing the system. I think I've led the way for 20 years," he said.
"So I think to be critical there is exaggerating. I'm the last guy to call a medical timeout. So I don't know what he's (Cash) talking about."
Federer said his leg had been hurting since his second-round match with Noah Rubin, and the pain spread during his match with Wawrinka.
"After he (Wawrinka) took a medical timeout, I thought I could also take one for a change and see if actually something like a massage during the match is actually going to help me," he said.
"It did a little bit potentially. I'm not sure. And then today I felt my quad midway through the second set, and the groin started to hurt midway through the third set."