No matter how famous you are, it appears, few can resist the appeal of the selfie.

As Barack Obama and David Cameron joined tens of thousands of South Africans paying their respects to Nelson Mandela at a memorial service in Johannesburg, they took advantage of the unusual number of dignitaries gathered in one place to pose for a self-portrait with Helle Thorning-Schmidt, the Danish prime minister (and daughter-in-law of Neil Kinnock).

Ignoring the etiquette tips that have proliferated online since 'selfie' was declared Oxford Dictionaries' word of the year, the three world leaders appeared to momentarily forget the solemnity of the occasion, adopting the mandatory cheesy grins. Michelle Obama maintained her dignity and refused to join in the antics.

Barack Obama jokes with Helle Thorning-Schmidt. Photograph: Matt Dunham/AP

The US president and the Danish leader were photographed laughing and chatting during the ceremony, while the US first lady looked on apparently unimpressed.

Obama and Helle Thorning-Schmidt in deep conversation. Photograph: Matt Dunham/AP

"While I will always fall short of Madiba's example, he makes me want to be a better man. He speaks to what is best inside us," Obama said when he addressed the gathering – and at times his wife appeared to agree.

Helle Thorning-Schmidttalks to Michelle Obama. Photograph: Matt Dunham/AP

But Michelle was also caught in conversation with Thorning-Schmidt herself, confounding those always eager to comment on the first marriage.

The Cameron-Obama-Thorning-Schmidt selfie soon went viral online, leading to a backlash from some who felt it was inappropriate behaviour for a funeral. But many remarked that the world leaders were simply joining in the South African spirit of celebrating, rather than mourning, Mandela. "Lighten up people, it was a celebration of life," tweeted ‏@s_phire.

"From everything I've read about Mandela this week, sounds like he'd have found the Obama selfie / Michelle Twitter gags pretty funny," tweeted Sam Parker.