Media playback is unsupported on your device Media caption Ed Sheeran performs The A Team at Glastonbury 2017

Pop star Ed Sheeran has headlined Glastonbury's Pyramid Stage, just six years after his debut at one of the festival's smallest venues.

In 2011, the star played the solar-powered Croissant Neuf stage, playing "to about 500 people".

On Sunday, he closed the festival, attracting a much younger audience than Friday and Saturday's headliners, Radiohead and Foo Fighters.

The 26-year-old admitted he was "very nervous but very excited" to be there.

"For those of you who haven't seen one of my shows before or haven't heard one of my songs, please pretend that you know them," he told the audience.

"For those of you who have, please sing all of the words."

"The aim of tonight is to lose our voices," he added. "I'm going to lose mine as well."

The audience took him up on the challenge; joining in wistfully as he sang the ballads Photograph and Thinking Out Loud.

They didn't quite keep up, however, with the spittle-flecked Take It Back - a whirlwind of wordplay in which Sheeran declared: "I'm not a rapper, I'm a singer with a flow."

The star played, as he usually does, without a band; using a loop pedal to layer his vocal and guitar lines and create a backing track live, on the spot.

This created problems during Bloodstream when his guitar slipped out of tune but, for the most part, the sound was impressive: Sheeran can build up or break down a song at will, a skill honed by years of relentless gigging in his teens.

Image copyright PA Image caption Sheeran attracted a significantly younger audience to the Pyramid Stage

Highlights included The A-Team, which he sang illuminated by the audience, who held their phones aloft, creating the impression of 80,000 fireflies bobbing around the fields of Worthy Farm.

Sheeran also invited traditional Irish band Beoga on stage to accompany him on Nancy Mulligan, a song about his paternal grandmother.

It was a moment that reeked of cheese but, watched from the side of the stage by his grandfather, Sheeran made it seem genuine.

This is the secret to his appeal. His brand of pop can be innocuous and twee - but Sheeran sells it with an earnest, everyman shtick that demolishes the divide between artist and audience.

However you respond to his music, it is clear he strikes a chord, especially with the YouTube generation who prioritise relatability over the preening mannerisms of, say, Mick Jagger.

Sheeran exploits it effortlessly. On headlining Glastonbury, he told the crowd: "I'd like to say it was a dream of mine, but I never thought I'd get to the point where I was playing this stage, let alone headlining it."

Image copyright Rex Features Image caption Sheeran may have been on stage alone, but his impressive set helped fill Worthy Farm with colour

And to Glastonbury itself, Sheeran's appeal to under-30s is paramount: those are the fans the festival needs to replenish its audience and survive.

That's why this year saw more pop and grime acts than ever, from Charli XCX to Katy Perry; from Wiley to Stormzy.

Killer surprise

On Sunday, the festival also saw sets from Royal Blood, Courteeners, Foo Fighters, The Jacksons, Radiohead and The Killers - who played a secret show on the John Peel stage on Sunday evening.

"They say you play the John Peel Stage twice in your career - once on the way up, and once on the way down," said frontman Brandon Flowers.

"It's great to be back."

Earlier in the day, the Pyramid Stage briefly turned into Studio 54, with consecutive sets from Bee Gee Barry Gibb and funk band Chic drawing one of the biggest crowds of the weekend.

And LA band Haim literally brought the audience at The Other Stage to its knees.

The band, who were debuting songs from their new album, Something To Tell You, encouraged the crowd to dance lower and lower towards the ground until, eventually, they were lying down on the grass.

"All I wanted was a dance party," bassist Este Haim told the BBC afterwards, "and then Glastonbury danced with me. We tangoed."

Media playback is unsupported on your device Media caption Haim reflect on their triumphant set

Sunday also saw sets from Shaggy, Emeli Sande, London Grammar and Biffy Clyro, who threw down the gauntlet to Sheeran with a ferocious volley of rock riffs on the Pyramid Stage.

There is no Glastonbury in 2018, meaning that there are 731 days until Worthy Farm opens its gates again.

The cows will be pleased.

Follow us on Facebook, on Twitter @BBCNewsEnts, or on Instagram at bbcnewsents. If you have a story suggestion email entertainment.news@bbc.co.uk.