Cameron was responding to a letter from British actor and writer Stephen Fry, who called for the games to be taken away from Sochi, Russia, because of a new Russian law that bans "propaganda of nontraditional sexual relations" and imposes fines on those holding gay pride rallies.
Fry was among hundreds of people protesting in London on Saturday against that law, which he called "preposterous." The demonstrators waved placards calling for a boycott of Sochi, and banners with the Olympic rings rendered in black. They chanted "Gay Rights for Russia" as they protested across from Downing Street, where Cameron resides.
The British prime minister thanked Fry for his note, saying on Twitter that he shares Fry's "deep concern about the abuse of gay people in Russia."
"I believe we can better challenge prejudice as we attend, rather than boycotting the Winter Olympics," Cameron said.
Cameron's words echoed remarks made a day earlier by President Barack Obama, who said he was deeply offended by Russia's new law cracking down on gay rights activism but does not think it is "appropriate" to boycott the Olympics.
While Fry acknowledged Saturday that it was "probably not realistic to call for a move or a boycott," he urged athletes to make symbolic protests at the games, such as crossing their arms over their chests.
Such a move would "show they are thinking of the gay people of Russia who are being tormented and brutalized every day," Fry told the BBC.