MELBOURNE, Australia -- Roger Federer won his 18th Grand Slam title and put some extra distance on the all-time list between himself and Rafael Nadal, the man he beat 6-4, 3-6, 6-1, 3-6, 6-3 in a vintage Australian Open final on Sunday night.

It was the 35-year-old Federer’s first major title since Wimbledon in 2012, his first in Australia since 2010, and it reversed the status quo against his nemesis, Nadal.

“Against Rafa it’s always epic,” Federer said in a television interview. “This one means a lot to me because he’s caused me problems over the years.”

Both players were returning from extended layoffs - Federer for six months after Wimbledon with an injured left knee; Nadal for a couple of months with an injured left wrist - and were seeded 17th and ninth respectively.

Get Breaking News Delivered to Your Inbox

“I wasn’t sure I was going to make it here but here I am - we made it,” Federer said after accepting the trophy from Australian great Rod Laver, who lends his name to the main stadium at Melbourne Park. “I would have been happy to lose too, to be honest. The comeback was perfect as it was.

“Tennis is a tough sport, there’s no draws. If there was going to be one, I would have been happy to have it tonight and share it with Rafa, really.”

Federer had lost six of the previous eight Grand Slam finals he’d played against Nadal, and was 11-23 in their career meetings.

After twice coming back from a set down, Nadal was a break up in the fifth - until Federer regained control and ultimately became the first man in the Open era to win three of the Grand Slam events at least five times (7 Wimbledon, 5 U.S. Open, 5 Australian Open and 1 French Open title).

Nadal remains equal second with Pete Sampras on the all-time list with 14 - and none since the 2014 French Open.

After four sets where the momentum swung alternately from one player to the next, the fifth had all the tension and drama that these two players are famous for.

Nadal went up an early break and it seemed as if the injury time-out Federer needed after the fourth set may have been an indicator of things to come.

But the Swiss star rallied, and broke back in a pivotal sixth game and took control in a period when he won 10 straight points.

Nadal saved three break points in the eighth game but lost momentum again when Federer finished off a 26-shot rally - the longest of the match - with a forehand winner down the line.

Consecutive forehand errors gave Federer the pivotal break for 5-3, but Nadal made him work for the very last point.

Serving for the match, Federer had to save two break points with an ace and a forehand winner.

At deuce, he was called for a double-fault but challenged the out call on his second serve. The call was overturned, and he got to play two.

Not long after, he fired an ace to get his second match point and hit a forehand crosscourt winner.

His celebrations were delayed, though, when Nadal challenged the call. Federer watched the replay on the stadium screen, and leaped for joy when it showed his last shot was in. His 100th match at the Australian Open ended with his fifth title at Melbourne Park.

“Congratulation to Roger ... Just amazing, the way he’s playing after such a long time of him not being on the tour,” Nadal said. “For sure, you have been working a lot to make that happen. So congratulations.”

Nadal spent two months recovering from a left wrist injury before heading to Brisbane for a warmup tournament. He had no expectations of reaching the final in Australia.

“I had some hard time not being able to compete in full condition. ... some injuries, well not new for me,” Nadal said. “I fight a lot these two weeks. Today, a great match, probably Roger deserved it a little bit more than me.”

No two players had met more often in Grand Slam finals in the Open era, and Nadal had previously dominated. But they hadn’t met in a major final since the 2011 French Open, won by Nadal.

Three months ago, they were both on breaks when Federer joined Nadal in Mallorca for the opening of the Spaniard’s tennis academy and the pair joked about ever being able to contend for majors again.

Yet here they were, first Grand Slam tournament of the season, renewing the classic rivalry that saw them dominate tennis a decade ago.

The long-odds final - No. 9 against No. 17 - unfolded after six-time champion Novak Djokovic was upset by No. 117-ranked Denis Istomin in the second round and top-ranked Andy Murray, a five-time losing finalist in Australia, went out in the fourth round to 50th-ranked Mischa Zverev.

Federer beat Zverev in the quarterfinals and U.S. Open champion Stan Wawrinka in an all-Swiss semifinal to reach the championship match.

Wawrinka took to Twitter to congratulate him.