The chart-dominating pop star will close the event on Sunday, 25 June, in his only festival appearance this year.
On a short Instagram film, he described the news as “awesome”, ending speculation about 2017’s headliners.
The full line-up will be announced at a later date. Tickets for the festival, in Somerset, have already sold out.
Sheeran first played Glastonbury in 2011, appearing on the BBC Introducing stage before his debut album – +, or Plus – had ever been released.
He returned for a slot on the Pyramid Stage in 2014, memorably leading the audience in a mass sing-along to his smash hit Sing.
He returns to Worthy Farm as one of the world’s biggest pop stars, having sold four million copies of his third album, Divide, in the last 10 days.
The star also dominates the singles chart, with all 16 of the tracks on his album residing in the Top 20.
Radiohead are the Friday night headliners, making their first UK festival appearance since 2011.
Foo Fighters take the Saturday night slot, making up for 2015 when they were forced to cancel.
A handful of other acts have confirmed themselves for the festival – including Laura Marling and London Grammar.
Lady Gaga is also rumoured to be playing, after being spotted backstage last year.
The festival bill is usually announced in early April, once fans have paid the remaining balance on their tickets.
Organiser recently revealed that “twice as many bands” had been booked for this year’s event, which runs from 21 to 25 June at Worthy Farm in Somerset.