After coming through the longest match in the tournament's history to reach the championship match, top-ranked Nadal needed 4 hours, 23 minutes to win it 7-5, 3-6, 7-6 (3), 3-6, 6-2.
Federer, who was trying to equal Pete Sampras' record 14 major titles, has now lost to Nadal the last three times they've met in Grand Slam finals.
U.S. & World
The 27-year-old Federer, so dominant when he won three of the four majors in both 2006 and 2007, has now lost finals on three different surfaces to Nadal.
Nadal, who has four consecutive titles on clay at Roland Garros and beat Federer on grass in a five-set epic at Wimbledon last year, became the first Spaniard to win the Australian title.
He has now won five of the seven Grand Slam finals he's played against Federer and is 13-6 overall against the Swiss star.
Nadal beat Federer in the last French Open and Wimbledon finals and replaced him at No. 1 last August after winning the gold medal at the Beijing Olympics.
Federer, who turned around his last season with a U.S. Open title, saved two championship points from 15-40 in the eighth game of the fifth set but sent a forehand long on the third match point.
Nadal flopped onto his back, then got up and raced to shake hands.
The players put an arm around the other's shoulder at the net as they walked off the court.
Drenched in sweat, Nadal raised his fist, applauded the crowd's standing ovation, then went over to shake hands with his coach and other supporters.
Federer, in tears, was barely able to speak at the presentation.
Although Federer actually won one more point — 174-173 — his serve let him down all too frequently. He connected on only 51 percent of his first serves, and it seemed all of his six double-faults came at critical times.
And as the pressure ratcheted up in the fifth set, it was Federer who wilted, not Nadal. Federer had six winners and 14 unforced errors in the set, while Nadal had just two unforced errors and dropped only three points in four service games.
With more Swiss flags than Spanish national colors, the crowd was buzzing even during warmups.
Despite flashes of brilliance, what they got wasn't always great tennis early, but there was no shortage of drama.
Both players started tight, committing uncharacteristic errors. Knowing that weak shots would be punished, they were pushing the limits.
They exchanged service breaks in the first two games. Normally calm on court, Federer pumped his fist after breaking for a 4-2 lead only to double-fault when facing break point in the next game.
Nadal got the key break with Federer serving at 5-5. The crowd was stunned when he smacked a forehand wide on an easy short ball to make it 15-40, and Nadal followed with a forehand passing shot winner, then held for the set.
With Nadal seemingly getting to everything and ripping winners, Federer was looking tentative and hesitating to charge the net.
But he started putting winners together and cutting his mistakes in the second set. After Nadal broke for a 4-3 lead, Federer broke the Spaniard's next two service games, taking a 5-3 lead after converting his fifth break point of the game. He then held to level the match.
Then the level intensified. One fan shouted: "Make him work, Roger," referring to questions whether Nadal's 5-hour, 14-minute semifinal win over fellow Spaniard Fernando Verdasco on Friday might leave him tired. But he showed few signs of fatigue.
Amid a series of rallies lasting more than 20 shots, Nadal saved six break points in his last two service games in the third set, and Federer fended off a set point while serving at 5-6.
A lunging backhand volley winner gave Nadal a 6-3 lead in the tiebreaker, earning him chants of "Rafa!" and Federer double-faulted.
Federer saved five break points while serving at 2-2 in the fourth set, then broke Nadal in the next game for a 4-2 edge.
He closed with a service winner to even it at two sets apiece.
Nadal broke Federer for a 3-1 lead and the clock ticked past midnight in the next game, taking the Australian Open into a third week.
It was the first men's final to go to five sets since Mats Wilander beat Pat Cash in 1988, the first at Melbourne Park.