Federer won his 11th Grand Slam - three away from Sampras' record
The world number one prevailed 7-6 4-6 7-6 2-6 6-2 after three hours and 45 minutes of breathtaking tennis.
Federer looked to be in control with a two sets to one lead, but the tireless Nadal broke twice to force a decider.
After saving four break points, Federer powered a superb forehand down the line to lead 4-2 before sealing an epic win.
After taking victory, Federer collapsed to his knees as Borg, watching from the Royal Box, joined the rest of an enraptured Centre Court crowd in giving the champion and his beaten opponent a standing ovation.
It was no more than they deserved, Federer winning by far the toughest match of his five-year reign.
"Each one is special but to play a champion like Rafa, it means a lot and equalling Bjorn's record as well..." a tearful Federer told BBC Sport.
"He's a fantastic player and he's going to be around so much longer so I'm happy with every one I get before he takes them all!
"It was such a close match. I told him at the net that he deserved it as well. Well... I'm the lucky one today."
Federer, in his ninth Grand Slam final in a row and 13th overall, made a superb start, hitting seven winners before Nadal had managed one as he surged into a 3-0 lead.
The Spaniard settled, though, and at 1-3 unleashed two magnificent passing shots from well behind the baseline to rock Federer and broke back.
But a first set of often dizzying quality was decided by the scrappiest of tiebreaks, Federer winning it 9-7.
The second set looked to be heading for another tiebreak until it turned dramatically in game 10.
Federer hit a first serve which both players appeared to think was wide. Nadal scrambled back the return but an off-balance Federer made a mess of his reply.
That gifted Nadal two set points and the Spaniard whipped a backhand down the line to level the match, punching the air in celebration.
The quality somehow hit a new peak in the third set, scintillating rallies and dazzling winners becoming the norm.
At 5-4 down, Federer faced deuce but produced two spectacular winners, an angled backhand smash and a jaw-dropping volley off a dipping Nadal forehand, to come through before stepping on the power to take the tiebreak 7-3.
With a two sets to one lead, Federer took a toilet break and when he returned, Nadal was ready for an ambush, earning his first break point since the second set and taking it with a magnificent forehand crosscourt return which left a net-bound Federer floundering.
More drama followed when at 2-0 and 30-30 on Federer's serve, Nadal challenged a baseline call, with Hawkeye deciding his backhand had clipped the back of the line.
A clearly rattled Federer, an outspoken critic of Hawkeye, dumped a routine forehand into the net to go a double-break down and let rip at the umpire during the changeover, blaming the electronic system for "killing" him.
Nadal, despite having treatment on a knee injury at 4-1, took the set comfortably to force Federer into his first five-set match at Wimbledon since he beat Pete Sampras in 2001.
And the Spaniard may look back with regret at the chances he had in the decider.
At 1-1 and 2-2, he engineered a 15-40 lead but Federer's serve proved impregnable and it was no surprise when Nadal himself succumbed to the pressure.
Federer delivered a rare show of emotion when his forehand landed on the line, looking up to his support camp and roaring with delight.
Nadal fought valiantly to the end but Federer had hit supreme form, swatting away a volley on his second match point to take his place in Wimbledon's history books.