Glastonbury co-organiser Emily Eavis confirmed the former Beatle would be joining the 2020 line-up on Instagram, calling it a "dream come true".
She wrote: ""IT'S REAL!! So excited. Having Paul McCartney coming back to headline the Pyramid next year is an absolute dream come true. There really was no one that we wanted more for the 50th anniversary."
Sir Paul also shared the news on his official Twitter page, writing: "Hey Glasto - excited to be part of your Anniversary celebrations. See ya next summer!"
Earlier in the day, the 77-year-old singer posted a cryptic image on social media, showing composer Philip Glass, actor Emma Stone and the late Chuck Berry.
The black and white snap led fans to link together the stars' surnames to spell out "Glastonbury".
McCartney's performance will follow the 50th anniversary of The Beatles iconic Abbey Road album earlier this year.
McCartney released the solo album Egypt Station last year, his first in five years.
He has headlined the Somerset festival just once before, back in 2004.
So far, only one other act has been confirmed for Glastonbury 2020, with former Supreme star Diana Ross taking the legend slot.
Other performers rumoured to be in the mix include Taylor Swift, Madonna and Kendrick Lamar.
Spice Girls fans have also been getting excited with unconfirmed reports that a full line-up return could be on the cards.
This year's festival was headlined by Stormzy, The Killers and The Cure, while Kylie Minogue performed in the legends slot.
© Sky News 2019