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.
Murray 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.
It was a momentous win for Federer, who tied Pete Sampras with seven Wimbledon titles and extended his overall grand slam record to 17.
Today he returns 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 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 momentous 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.
ANDY MURRAY FACTFILE
1987: Born May 15, Dunblane, Scotland.
1999: December - Wins junior Orange Bowl title in Miami.
2004: September - Becomes first British winner of US Open boys' title, beating Ukrainian Sergiy Stakhovsky.
2005: March - Becomes youngest British Davis Cup player, aged 17, in match against Israel.
June - Defeats Radek Stepanek to become first Scot to reach third round at Wimbledon. Loses to David Nalbandian.
October - Reaches first ATP final at Thailand Open, losing to Roger Federer.
2006: February 20 - Claims first ATP title by beating Lleyton Hewitt in San Jose.
February 28 - Moves above Tim Henman and Greg Rusedski in rankings to become British number one.
April 14 - Splits from coach Mark Petchey.
July 3 - Loses to Marcos Baghdatis in fourth round at Wimbledon.
July 26 - American Brad Gilbert appointed Murray's new coach.
2007: January 22 - Loses five-set thriller to Rafael Nadal in Australian Open fourth round.
February 18 - Defends San Jose title with victory over Ivo Karlovic.
October 28 - Wins St Petersburg Open, beating Fernando Verdasco.
November 14 - Splits with coach Gilbert.
2008: January 5 - Beats Stanislas Wawrinka to win Qatar Open.
February 17 - Wins Open 13 tournament in Marseille, beating Mario Ancic.
July 2 - Loses to Nadal in Wimbledon quarter-finals.
August 3 - Defeats Novak Djokovic in Cincinnati to claim first Masters Series title.
August 12 - Suffers first-round defeat by Yen-Hsun Lu of Chinese Taipei at Beijing Olympics.
September 7 - Beats top seed Nadal in semi-finals of US Open to reach first grand slam final.
September 8 - Beaten 6-2 7-5 6-2 by defending champion Federer in US Open final.
September 21 - Wins his singles matches but Great Britain lose to Austria to be relegated from Davis Cup World Group.
October 19 - Wins Madrid Masters with victory over Gilles Simon.
October 26 - Wins St Petersburg Open, beating Kazakhstan's Andrey Golubev.
2009: January 11 - Wins Qatar Open, beating Andy Roddick.
February 15 - Wins ABN AMRO World Tennis Tournament in Rotterdam, beating Nadal.
March - Wins Miami Masters, beating Djokovic.
May 11 - Overtakes Djokovic to become world number three.
June 2 - Loses to Fernando Gonzalez in French Open quarter-finals.
June 14 - Becomes first British player since 1938 to win Queen's Club title, beating James Blake in the final.
July 3 - Reaches first Wimbledon semi-final but loses 6-4 4-6 7-6 7-6 to Roddick.
August 16 - Wins Montreal Masters with victory over Juan Martin Del Potro, and becomes world number two.
November 8 - Wins comeback event in Valencia after wrist injury. Later finishes year at world number four.
2010: January 31 - Loses 6-3 6-4 7-6 to Federer in Australian Open final.
May 30 - Beaten by Tomas Berdych in French Open fourth round.
July 2 - Loses Wimbledon semi-final 6-4 7-6 6-4 to Nadal.
July 27 - Splits with coach Miles Maclagan after two and a half years.
August 15 - Beats Nadal and Federer as he defends his Masters title in Toronto.
October 17 - Beats Federer in final to win Shanghai Masters.
November 27 - Loses 7-6 3-6 7-6 to Nadal after more than three hours in a classic semi-final at ATP World Tour Finals in London.
2011: January 30 - Beaten 6-4 6-2 6-3 by Djokovic in Australian Open final.
June 3 - Loses 6-4 7-5 6-4 to eventual champion Nadal in French Open semi-final.
June 13 - Beats Tsonga to win AEGON Championships at Queen's Club.
July 1 - Loses 5-7 6-2 6-2 6-4 against Nadal in Wimbledon semi-final.
August 21 - Wins Western & Southern Open crown in Cincinnati when world number one Novak Djokovic retires injured when trailing 6-4 3-0.
September 10 - Loses 6-4 6-2 3-6 6-2 to Rafael Nadal in US Open semi-final.
September 18 - Helps Great Britain win Davis Cup promotion with a 5-0 victory over Hungary in Glasgow.
October 2 - Beats American Donald Young 6-2 6-0 in Thailand Open final.
October 9 - Beats Nadal 3-6 6-2 6-0 to win Japan Open final.
October 16 - Completes hat-trick of tournament victories by beating David Ferrer 7-5 6-4 in Shanghai Masters final, to take him above Federer and to number three in world rankings.
November 22 - Pulls out of the Barclays ATP World Tour Finals with a groin injury. Federer's victory in the tournament takes him back to world number three.
December 31 - Hires eight-time grand slam winner Ivan Lendl as his new coach.
2012: January 27 - Loses 6-3 3-6 6-7 6-1 7-5 to Djokovic in epic Australian Open semi-final lasting four hours and 50 minutes.
June 6 - Murray's French Open run ends in the quarter-finals with defeat by David Ferrer.
July 6 - Reaches Wimbledon final for the first time with a 6-3 6-4 3-6 7-5 victory over Jo-Wilfried Tsonga.
July 8 - Federer denies Murray in the Wimbledon final, winning 4-6 7-5 6-3 6-4 to land a record-equalling seventh title. Murray breaks down in tears in his on-court interview, saying: "I'm getting closer."
COMMENT RULES: Comments that are judged to be defamatory, abusive or in bad taste are not acceptable and contributors who consistently fall below certain criteria will be permanently blacklisted. The moderator will not enter into debate with individual contributors and the moderator’s decision is final. It is Belfast Telegraph policy to close comments on court cases, tribunals and active legal investigations. We may also close comments on articles which are being targeted for abuse. Problems with commenting? email@example.com