In response to a high-profile intervention from broadcaster Stephen Fry calling for the Games to be moved, Mr Cameron said he had shared the “deep concern” about the abuse of gay people in Russia.
But writing on Twitter the Prime Minister said: “I believe we can better challenge prejudice as we attend, rather than boycotting the Winter Olympics.”
Fry had urged the Prime Minister to support moves to strip Russia of the 2014 Winter Olympics over concerns about anti-gay laws passed in the country.
The broadcaster, writing in an open letter on his website, compared the situation to the decision to hold the 1936 games in Nazi Germany and said President Vladimir Putin “is making scapegoats of gay people”.
He said: “An absolute ban on the Russian Winter Olympics of 2014 in Sochi is simply essential. Stage them elsewhere in Utah, Lillehammer, anywhere you like. At all costs Putin cannot be seen to have the approval of the civilised world.”
In a Twitter post to the QI host - who is a keen user of the website - Mr Cameron said: “Thank you for your note @stephenfry. I share your deep concern about the abuse of gay people in Russia...
“However, I believe we can better challenge prejudice as we attend, rather than boycotting the Winter Olympics.”
In his open letter Fry said the Prime Minister was “a man for whom I have the utmost respect”.
He added: “As the leader of a party I have for almost all of my life opposed and instinctively disliked, you showed a determined, passionate and clearly honest commitment to LGBT (lesbian, gay, bisexual, and transgender) rights and helped pushed gay marriage through both houses of our parliament in the teeth of vehement opposition from so many of your own side. For that I will always admire you, whatever other differences may lie between us. In the end I believe you know when a thing is wrong or right. Please act on that instinct now.”
It comes after politicians in Russia’s lower house of parliament, the Duma, passed a law imposing heavy fines for providing information about homosexuality to people under 18.
Last month, the International Olympic Committee said it would “work to ensure that the Games can take place without discrimination against athletes, officials, spectators and the media”.
It said: “To that end, the IOC has received assurances from the highest level of government in Russia that the legislation will not affect those attending or taking part in the Games.”