Sheeran arrived unannounced at House in Paradise at O Beach Ibiza on Monday and jumped on stage for the set alongside the in-house DJs in front of a large crowd.
Footage showed the pop star launch into Shape Of You before playing I Want It That Way by the Backstreet Boys, during which he jumped into the crowd to sing with fans.
He returned to the stage to finish with Sweet Caroline and Hit Me Baby One More Time by Spears.
House In Paradise promoter Joshua Makinson said “I was absolutely blown away that Ed has come to House in Paradise at O Beach.
“We’ve had artists turn up in the past and perform but to have one of the biggest pop stars in the world perform is magical.”
It comes shortly after Sheeran announced a surprise collaboration with popular video game series Pokemon.
The track, called Celestial, will be released on Thursday and arrive with an animated music video created by the studio behind the games.