Tory MPs cheered as the prime minister mocked Labour for deciding to vote in favour of an EU referendum despite its pre-election opposition to the government's plan.
Harman, Labour's acting leader, told Cameron: "He won the election, he is the prime minister he doesn't need to do ranting and sneering and gloating he can just answer the questions." She added: "Frankly he should show a bit more class."
Cameron reacts to being told to stop 'gloating'
Harman later accused the prime minister of using prime minister's questions as a "gloating session" rather than a chance to answer questions from MPs. "Go right ahead and gloat," she said.
Cameron had been poking fun at Harman by quoting from an interview in which Labour's acting leader had said voters were "relieved" the Tories had won. "It must be the first time someone has ever been accused of gloating whilst quoting the leader of the opposition," he said.