London (CNN) -- Legislation to allow same-sex marriage in England and Wales won passage Tuesday in the House of Commons.
The vote was 366 for, 161 against. The bill now goes to the House of Lords, where it will face further opposition.
A rebellion within Prime Minister David Cameron's Conservative Party threatened to derail the bill.
Tuesday brought the second day of discussions on the legislation. Members of Parliament voted Monday on a series of amendments to the Marriage (Same Sex Couples) Bill.
Cameron backs the bill but his commitment to it has put him at odds with many in his own party and its grassroots supporters. The Conservatives govern in coalition with the Liberal Democrats.
The bill was kept on track Monday thanks to the support of members of the opposition Labour Party, who voted to oppose an amendment that many Conservative rebels backed.
Same-sex marriage: Who will legalize it next?
The amendment, which was put forward by MP Tim Loughton, proposed extending civil partnerships to heterosexual couples as well as same-sex couples.
Minister for Women and Equalities Maria Miller, the sponsor of the same-sex marriage bill, argued that this would result in significant expense and delay, thus derailing the whole bill.
Labour leader Ed Miliband tweeted Monday: "David Cameron's inability to control his party must not be allowed to wreck the Equal Marriage Bill. Labour's commitment unwavering."
A law recognizing civil partnerships in England and Wales was passed in 2004.
The Church of England is among the religious bodies opposed to the new legislation.
The issue of same-sex marriage has exposed painful divisions within Cameron's party, with many lawmakers already fractious over his position on Europe.
Under pressure, Cameron's government last week published a draft bill promising a referendum by 2017 on Britain's membership of the European Union. The Conservative Party faces a political threat from the UK Independence Party, which has vowed to take Britain out of Europe.
Controversy has also blown up following weekend UK media reports that quoted a senior ally of Cameron describing party activists as "swivel-eyed loons."
In an effort to dampen the flames, Cameron sent an e-mail late Monday to party supporters, according to UK media reports, saying he was proud of their work and would "never have around me those who sneered" at them.
Same-sex marriage around the world
The issue of same-sex marriage has also prompted wide disagreement elsewhere.
On Saturday, French President Francois Hollande signed into law a bill allowing marriage and adoption for same-sex couples despite vocal opposition from many conservatives and the Catholic Church.
The step made France the ninth country in Europe to allow same-sex marriage.
If Uruguay and New Zealand enact legislation approved by their lawmakers as expected, the count of nations worldwide allowing same-sex marriage will rise to 14.
The first same-sex couples walked down the aisle in the Netherlands in 2001, with others following suit in Canada, South Africa, Belgium and Spain. Argentina was the first Latin American nation to legalize such marriages, in 2010. Other countries on the list are Denmark, Iceland, Norway, Portugal and Sweden.
Many countries remain split over the issue. A Brazilian court this week issued a directive removing a barrier that had limited same-sex marriage, but no bill has made it through Congress.
In the United States, the question went before the Supreme Court and justices are deliberating over the matter.
Twelve U.S. states and the District of Columbia have legalized same-sex marriage. On the other side, many states have specific laws blocking same-sex couples from legally marrying.