The former Beatle will top the bill on the Pyramid Stage on Saturday 27 June, a week after his 78th birthday, after not playing at the event for 15 years.
Co-organiser Emily Eavis said: “There really was no-one that we wanted more for the 50th anniversary.”
The star teased the announcement on Twitter on 18 November by posting a picture of Philip Glass, Emma Stone and Chuck Berry.
Eavis later confirmed the news, saying: “Having Paul McCartney coming back to headline the Pyramid for the second time next year is an absolute dream come true.”
Glastonbury 2004 was McCartney’s first ever festival set, despite playing more than 3,000 concerts.
Festival founder, Michael Eavis said: “Paul won the day for me. He hugged and kissed me afterwards but I should have kissed him.”
Sir Paul told Clash magazine of the gig: “It was a good night for us. It was a blast, and the audience seemed to love it. It was like, ‘Yeah man! People have come together!’ Very uplifting.”
The star is the first headliner to be confirmed for Glastonbury 2020. Diana Ross will play the Sunday afternoon “legends slot”, while other rumoured headliners include Taylor Swift, Kendrick Lamar, The 1975 and Foals.
Fleetwood Mac also prompted speculation that they would be playing at Glastonbury next year when Mick Fleetwood told fans at Wembley Stadium they still ‘had a big field to play’.
However, Emily Eavis said the band would not be playing as negotiations apparently stalled over money.
Micheal Evis stated: “I can’t afford them at the moment, but they said the other day that they really want to do it and if they don’t do it before they die they’ll go to hell.”