Melbourne, Australia (CNN) Even for the legendary Roger Federer, this was -- nearly -- unbelievable.

After missing the second half of last season with a knee injury, the Swiss star came back in style by winning the Australian Open Sunday and turning the tables on nemesis Rafael Nadal with a gripping 6-4 3-6 6-1 3-6 6-3 victory in just over 3 and a half hours.

The clash marked an extraordinary comeback for the duo, both of whom have battled recent injuries and are now older than most of their opponents.

"I don't think either one of us believed we were going to be in the finals at the Australian Open... four, five months ago, and here we stand in the finals," Federer said.

But Federer was obviously much the happier.

"This is beautiful, but it's still much better, the (other) trophy," Nadal said as he looked glumly at the runner-up trophy.

Federer wept when losing to Nadal in the 2009 Australian Open final in five sets. This time he cried tears of joy and vowed to celebrate deep into the morning.

Rafael Nadal, left, congratulates Roger Federer after the match.

26-shot rally

"We're going to party like rock stars," Federer said.

Never in his "wildest dreams" did the Swiss even expect to make the final, especially since he was handed a tough draw. So what was the 35-year-old -- the second oldest man behind Ken Rosewall to win a major in the Open Era -- thinking when bagging his record-extending 18th major and first since Wimbledon in 2012?

He compared the win in importance to the 2009 French Open when he claimed the clay-court major for the first and only time. Nadal was the man who had habitually stopped him in Paris.

"I waited for the French Open," he said. "I tried. I fought. I tried again and failed. Eventually I made it. This feels similar."

Federer had to do it the hard way, too, rallying from 3-1 down in the fifth. He rarely takes medical timeouts but did so entering the fifth set against Stan Wawrinka in the semifinals and at the same stage versus Nadal.

It was for the same issue, an upper leg complaint.

Yet he consistently threatened on the Nadal serve and finally got his reward for 3-3 -- after Nadal's forehand on game point clipped the tape and went wide.

In a game highlighted by a 26-shot rally that Federer won with a blistering forehand down the line, he broke again for 5-3 when a good, angled backhand return forced an error. That after Nadal dug out of 0-40 to get to deuce.

But there was still drama to come.

JUST WATCHED Is Roger Federer the best ever according to statistics? Replay More Videos ... MUST WATCH Is Roger Federer the best ever according to statistics? 02:21

In the last game, Federer fended off two break points with an ace and forehand winner. On a second match point his forehand cross-court was close to the line but ruled good. A challenge came from Nadal and the crowd roared when replays showed the ball to be touching the line.

It was, truth be told, an anticlimactic conclusion as Federer had to wait before finally celebrating. The two subsequently hugged and exchanged words at the net.

"It's slightly awkward to win this way," Federer said. "Nevertheless, emotions poured out of me. Of course I was seeing my entire support team, (wife) Mirka going bananas. It was cool."

Even if the hard courts and balls were quicker this year at the Australian Open -- aiding Federer's aggressive, flat-hitting game -- all the numbers suggested Nadal held the edge in the 35th installment of what many consider to be the best men's tennis rivalry of all time.

Nadal hadn't lost to Federer at a grand slam since Wimbledon in 2007. He was 7-2 in grand slam finals against his friend and 23-11 overall.

Huge implications

Perhaps Nadal's five-hour semifinal win over Grigor Dimitrov drained the 30-year-old. He indeed hinted as much.

Newly elected Hall of Famer Andy Roddick said last week the tussle might be the most important in men's grand slam history. If Nadal had prevailed, he'd have been only two majors shy of Federer.

But now the gap has widened to four, seemingly too much for Nadal to overcome even with his resurgence in Melbourne.

Nadal is always one to dwell on the positive and he said he'll walk away from Melbourne in good spirits, despite Sunday's reverse.

"I believe that if I have my body in the right conditions, I can have a great year because I feel I am playing well," said Nadal, who was bidding for a first major since 2014.

Whereas Federer dealt with the knee issue last year, most of Nadal's year was blighted by a wrist problem.

Prior to the defeat to Federer, Nadal snapped a three-match losing streak in fifth sets and gained morale boosting victories over the likes of Dimitrov, Wimbledon finalist Milos Raonic and the German with immense potential, Alexander Zverev.

"I am with big personal satisfaction," Nadal said. "I cannot say I am sad."

Federer's win over Nadal, meanwhile, was his fourth top-10 scalp of the event.

As Nadal took control of the match in the fourth, playing his best tennis, it almost didn't happen.

Nadal's forehand, however, was highly inconsistent and lacked depth, which may have been tied to fatigue.

"The shots didn't penetrate like they did before," Heinz Gunthardt, the former coach of Steffi Graf and an analyst for Swiss TV, told CNN. "Especially the forehand, there was nothing on it at times. Way too much spin.

"Honestly I thought Roger was going to win it even when he was behind 3-1 in the fifth. It was Roger that was dictating play."

Nadal was set to pounce early in the third but the first two games of the set proved eventful.

Federer led 40-0 on serve, only to face not one, not two, but three break points. On all three he slammed aces out wide. Aces would dig Federer out of trouble on at least half a dozen break points.

Key third set

Sagging, Nadal was broken in the ensuing game when Federer pounced on a return to force a forehand error. And unlike Federer -- who hit 20 aces -- Nadal wasn't able to get much help from his serve. He countered with four aces.

Federer's backhand -- his weaker wing often targeted by Nadal -- more than held up, too, including in the fifth. Eight of his 14 backhand winners came in the decider.

"Before the fifth he also hit it incredibly," co-coach Severin Luthi told a group of reporters. "I think here we can play like that, the court the way it is."

The last time two players over 30 played in a men's grand slam final was at the 2002 US Open, a swansong in another epic rivalry, between Pete Sampras and Andre Agassi.

Given the buzz generated by this final, let's hope it won't be the last duel between Federer and Nadal.

Tennis won Sunday. And so did Federer.