He made the decisive break in a marathon sixth game and broke again for 3-2 in the fourth set before sealing victory on his second match point in three hours 24 minutes.
"I played some of my best tennis in my last couple of matches," Federer told the crowd after lifting the trophy.
"I couldn't be more happy. It feels being great being back here as the winner and it's a great moment. It feels nice to have this trophy back after three years."
An emotional Murray struggled to hold himself together when he took the microphone after his first Wimbledon final.
"I am getting closer," Murray, who had twice lost to Federer in straight sets in grand slam finals, tearfully told the crowd. "I'd like to congratulate Roger. He played a great tournament and he's not bad for a 30-year-old."