Pictures taken inside the FNB Stadium in Soweto, South Africa, showed the two leaders smiling as they leaned in for a photo with Danish Prime Minister Helle Thorning-Schmidt.
However, Michella Obama appeared less than impressed, turning her head away as her husband stared into the smartphone's lens.
Photos of the three leaders squeezing in for the shot quickly went viral on the internet, with some Twitter users suggesting it was inappropriate behaviour at an event to remember Mr Mandela.
An estimated 50,000 South Africans flocked to the stadium to celebrate the anti-apartheid hero's life, as millions more watched on television around the world.
The service was one of the biggest ever gatherings of current and former heads of state.
Mr Obama, who was seen shaking hands with Cuban President Raul Castro during the event, was joined by former US Presidents George W Bush, Bill Clinton and Jimmy Carter.
Mr Cameron was accompanied by his predecessors Gordon Brown, Tony Blair and Sir John Major.
Other VIPs included U2 singer Bono and Oscar-winning actress Charlize Theron, who sat together in the stadium, and Francois Pienaar, who captained South Africa at the 1995 Rugby World Cup.
Neither Mr Obama nor Mr Cameron are strangers to selfie snaps.
The President posed for a photo with one of his supporters on the election campaign trail last year, while the Prime Minister was famously spotted taking a nap in the background of an Instagram picture taken by the sister of his wife Samantha.
:: Watch Sky News live on television, on Sky channel 501, Virgin Media channel 602, Freeview channel 82 and Freesat channel 202.