The Scot made his own history by taking the opening set, his first in a Grand Slam final, but the Swiss champion nicked the second set by breaking Murray.
And, after rain forced a lengthy delay for the roof to be put up over Centre Court, Federer was rejuvenated and outclassed Murray to win the third and fourth sets.
He had become the first British player to reach the final for 76 years, but couldn't convert the optimism of the first set into a winning position and had to settle for being runner-up in a Grand Slam again.
Ruefully, he said afterwards: "I'm getting closer," before shedding tears in the middle of Centre Court as mother Judy, father Willie, and girlfriend Kim Sears looked on. Unable to contain his emotion, he paid tribute to his supporters, and also praised Federer.
"I'm going to try this and it's not going to be easy," the 25-year-old said, to deafening applause. "First I would like to congratulate Roger, I was getting asked the other day after I won my semi-final, is this your best chance, Roger is 30 now? He isn't bad for a 30-year-old.
"He played a great tournament, he had some struggles early on with his back and showed what a fight he still has in him, so congratulations, you deserve it."
Speaking about "Team Murray", he said: "I'm going to try and not look at them because I'll probably start crying again but everyone who is in that corner over there, who has supported me...we did a great job, so thank you.
"And last of all to you guys," he said to the crowd. "Everybody always talks about the pressure of playing at Wimbledon, how difficult it is.
"It's not the people watching, they make it so much easier to play. The support has been incredible," he added, breaking down, as Judy Murray was also seen dissolving into tears.
It was a momentous win for Federer, who has tied Pete Sampras with seven Wimbledon titles and extended his overall grand slam record to 17.
Tomorrow he will return to the top of the rankings for the first time since May 2010, replacing Novak Djokovic, and will be only the second man, after Andre Agassi, to be ranked number one in his thirties.
Murray was the first British player to reach this final since Bunny Austin in 1938, two years after Fred Perry's last title, and he looked on course for a stunning victory when he won the opening set.
He was on top for much of the second set as well but Federer hit top form at the perfect moment to level the match and the Swiss was simply too good in the third and fourth, winning 4-6 7-5 6-3 6-4.
Murray played at a completely different level to his previous three grand slam finals, two of which he also lost to Federer, but the result was the same, and he joins coach Ivan Lendl in having lost his first four slam finals.The consolation for Murray is that Lendl went on to win eight.
The names in the Royal Box showed just what a huge day this was for British sport. Prime Minister David Cameron and the Duchess of Cambridge were in the front row, while David Beckham and wife Victoria had travelled over from the United States. Scotland's First Minister Alex Salmond and Mayor of London Boris Johnson were also in attendance and there was a huge roar as the players walked out onto court.
Murray led their head-to-head 8-7 going into the match but knew he had lost the two most important matches. The Scot had started nervously on both those occasions but today he was aggressive from the first point.
Instead it was Federer making the simple errors and it cost him as a forehand volley over the baseline handed Murray a break in the opening game. Federer quickly settled and took his chance to level at 2-2, drawing a backhand error from Murray.
The Swiss forced two break points in the eighth game but Murray held firm, finding the corner with a pinpoint volley on the second, and he got his rewards in the next game.
The fourth seed played a shot straight out of the book of his coach Ivan Lendl when he drilled a shot right at Federer's head, and Murray broke to lead 5-4 when his opponent netted a forehand. The crowd were on their feet, and the home hope served it out confidently.
But, as big as winning the first set was, there was still an awfully long way to go, and Federer came out firing at the start of the second with a hold to love.
The Swiss then engineered another break point on the Murray serve but, once again, the 25-year-old showed a cool head when it mattered most, forcing an error on the Federer backhand. It was a big hold for Murray, and he continued to make life very difficult for Federer, creating break points in the fifth and ninth games but coming up just short.
The crowd sensed their man was close to taking a real stranglehold on the match, but Federer is not the most successful grand slam player for nothing and, with Murray serving at 6-5 behind, he forced a set point. The Swiss usually lifts his game at such moments and he did so again, playing a perfect point, finishing it with a sublime drop volley.
It was a very painful set to lose for Murray so it seemed to the advantage of the Scot when the heavens opened at 1-1 in the third and the players were forced off for around 40 minutes while the roof was closed.
The general view before the match had been an indoor final would suit the Federer, taking the wind out of the equation and allowing him to take the ball even earlier. He certainly looked fired up, and Murray was not helped by two heavy falls in the sixth game.
The second gave Federer a break point and, although Murray saved that one, the pressure was relentless and on his sixth chance of an epic game, the Swiss broke through.
Murray's second serve had been one of the keys to his run to the final but he was struggling to win points with it against Federer and needed to improve his first-serve percentage.
The Scot threw everything at his opponent when he served for the set but it was not enough and Federer held to go two sets to one in front.
Murray faced a massively uphill struggle, especially the way Federer was playing. The Swiss had only lost one grand slam final from two sets to one up, against Juan Martin del Potro at the US Open in 2009.
Murray almost made the perfect start to the third set when he had a chance to break in the second game but he missed an attempted pass by millimetres. And his hopes took another huge blow when Federer broke again to lead 3-2, nailing an imperious backhand pass that left Murray rooted to the spot.
The crowd willed their man to a break when Federer served for the match, but it was not to be, the 30-year-old clinching victory on his second match point after three hours and 24 minutes when Murray hit a return just wide.
The Scot sat in his chair disconsolate as Federer savoured being back on top of the world, joining Rod Laver and Arthur Ashe in winning the Wimbledon title past his 30th birthday.