In the first of several votes required for its passage, the lower house of parliament backed the legislation by 400-175, but more than half of Cameron's 303 lawmakers voted against or abstained, signaling deep unease with it and his leadership.
During a debate that lasted more than six hours, many Conservative MPs denounced the legislation, saying it was morally wrong, not a public priority, and unnecessarily divisive, threatening a corrosive legacy of bitterness.
Conservative lawmaker Gerald Howarth told parliament that the government had no mandate to push through a "massive social and cultural change."
"This is not evolution, it's revolution," added Edward Leigh, another Conservative member of parliament, saying marriage was "by its nature a heterosexual union."
Although the vote went Cameron's way, many analysts believe he will now have to address a deep seam of discontent running through his party.
He made a last minute televised statement ahead of the vote, arguing gay marriage would make society stronger.
"I'm a big believer in marriage. It helps people to commit to each other, and I think that's why gay people should be able to get married too," he said.
He later hailed the result of the vote as "a step forward for our country."
Cameron is trying to perform a tricky balancing act: to reconcile his desire to show his party is progressive, with the views of many in it who are uncomfortable with such a reform.
Amid talk of a possible leadership challenge to Cameron, many Conservative lawmakers say the prime minister is sacrificing core party values on the altar of populism.
Such talk is rife among some Conservative lawmakers and follows a spate of articles in the British press in which a handful of MPs raised the possibility of ousting Cameron, a prospect most commentators regard as far-fetched before the next election in 2015.
Grievances against Cameron
Conservative MPs' grievances are many: that Cameron is "arrogant," that he is too fond of the European Union, that the party's policies have been diluted by its coalition partner after Cameron failed to win the last election outright, and a nagging fear that he will not win the next one.
The gay marriage initiative has infuriated rank-and-file party activists and a protest letter signed by 25 past and present chairmen of local Conservative associations warned that members were starting to resign over the issue.
Justin Welby, the newly elected Archbishop of Canterbury and head of the world's 80 million Anglicans, used his first comments after being confirmed on Monday to reiterate his own opposition to gay marriage.
Faced with strong opposition from the Anglican and Catholic churches, the law would not force them to conduct gay marriages, but critics say gay people may launch legal challenges.
A YouGov poll for the Sunday Times on Sunday showed 55 percent favored legalizing gay marriage, while 36 percent opposed it. However, the same poll showed the issue was not one that concerned most voters.
The new law proposes legalizing same-sex marriage in 2014. It would also allow civil partners to convert their partnerships into marriages.
Gay marriage supporters say that while existing civil partnerships for same-sex couples afford the same legal rights as marriage, the distinction implies they are inferior.
In a sometimes emotional debate on Tuesday, several gay MPs from different parties took to their feet to commend the bill, describing the prejudice they had suffered growing up.
"Millions will be watching us today," said Nick Herbert, a gay Conservative MP. "Not just gay people but people who want to live in an equal society."
The vote was warmly welcomed by Cameron's junior coalition partners, the Liberal Democrats, and by the opposition Labour party, while gay rights group Stonewall called the result "a truly historic step forward."
Tuesday's vote in the House of Commons was "free," meaning MPs were able to vote according to their conscience, rather than under party orders.
The bill is still many stages away from becoming law, and some of its opponents called on Cameron after the vote to consider amending it to appease their concerns, promising they would try to frustrate its progress through parliament.
Warning of divisions
Peter Kellner, president of pollster YouGov, said he felt the parliamentary rebellion would hurt the Conservative party.
"For Cameron, gay marriage is part of his attempt to persuade the voters that his party belongs to modern, 21st century Britain," he wrote on the pollster's site.
"But the divisions that the gay marriages bill has unleashed ... threaten to send an altogether different message: that the Tories are divided, out of touch and prone to quarrel over issues of little concern to most voters."
With the next election still two-and-a-half years distant, there is a risk that internal party splits over issues like gay marriage could fester and turn what for now is only talk of a possible leadership challenge into the real thing.
"David Cameron has split the Conservative Party in half on gay marriage and failed to win a majority of Tory MPs. Labour win," Jackson, the Conservative MP, wrote after the vote.