Federer, playing in his eighth Wimbledon final and 24th Grand Slam championship match, won 4-6, 7-5, 6-3, 6-4 to join Pete Sampras and William Renshaw as a seven-time champion.
The Swiss great, who has also regained the world number one ranking, is just the third man over 30 to win Wimbledon following Rod Laver in 1969 and Arthur Ashe in 1975.
Murray, 25, bidding to be the first British man since Fred Perry in 1936 to win Wimbledon, has now lost all four Grand Slam finals in which he has appeared.
"It equals me with Pete Sampras, who's my hero, so it feels amazing," said Federer, whose last Wimbledon title was in 2009 and was without a major since the 2010 Australian Open.
"It feels great being back here as the winner. I think I played some of my best tennis in the last couple of matches. I couldn't be more happy."
Federer, who dominated the final after the Centre Court roof was shut early in the third set, admitted he had felt the sense of occasion with Murray chasing down history.
"Today was unique because of playing Andy. Obviously, being able to play or finish a match under the roof, I don't think that's ever been done before here for a final. I know the occasion and how big it was for Andy and myself."
Murray, the first British man to reach a Wimbledon final since Bunny Austin in 1938, broke down in tears at the closing ceremony, delivering his speech but faltering on numerous occasions.
"I'm getting closer," said an emotional Murray, who had to gather himself before continuing.
"I'm going to try this but it won't be easy. Firstly I'd like to congratulate Roger. I was asked the other day if this is my best chance? Roger's 30. He's not bad for a 30-year-old."
In the opening exchanges of this eagerly-anticipated final, Murray was the stronger player, making the most of his five-year advantage as Federer looked fatigued and ragged.
However, once the £80 million roof was shut the momentum shifted and Federer stormed into the ascendancy.
With the Duchess of Cambridge, sister Pippa Middleton, Australian great Rod Laver, British Prime Minister David Cameron and even the Beckhams looking on from the Royal Box, it was the Briton who started the stronger.
Murray, defeated by Federer in the 2008 US Open and 2010 Australian Open finals without winning a set, broke in the first game when an uncharacteristic nervy Swiss ballooned a drive volley and that break was backed up by a hold.
Federer held and retrieved the break before Murray survived two break points in the eighth game.
He broke to lead 5-4 as Federer netted a forehand having had to take evasive action to avoid a Murray forehand missile.
The Scot then wrapped up the opener -- it was the first set Murray had won in his three Grand Slam finals, with Federer's 16 unforced errors to his opponent's five proving key.
Murray saved a break point in the second game of the second set while Federer, the first 30-year-old in the final since Jimmy Connors in 1984, saved two in the fifth.
The two men served a pair of love games as Federer led 4-3 while Murray wasted two break points in the ninth game as the six-time champion clung on for a 5-4 advantage.
The Briton again served a love game for 5-5.
But Federer held and suddenly carved out a set point with a magical drop volley in the 12th game which caused Murray to push a lob long.
Another immaculate drop volley off his toes gave him the set 7-5.
At 1-1 and 40-0 for Federer in the third, heavy rain drove the players off court for 40 minutes and the roof was closed.
In a dramatic sixth game, which lasted 20 minutes and went to 10 deuces, Murray took three tumbles to the ground, surrendered a 40-0 lead and Federer broke on a sixth break point for a 4-2 lead.
A ninth ace of the contest gave Federer the set 6-3 and a two sets to one lead.
Suddenly, the life and vibrancy seeped out of Murray.
He felt his lower back, Victoria Beckham looked even more sombre, and the Scot slipped 3-2 down off a killer, crosscourt backhand drive.
A 12th ace in the 10th game took Federer to two match points, the first of which was saved but Murray went wide on a forehand to hand Federer victory.