The gay marriage bill has been saved after Ed Miliband agreed at the last minute to vote against an amendment to extend civil partnerships to heterosexual couples that had prompted government warnings that it would derail the entire measure.

The Labour leader, who had planned to abstain in a Commons vote on the amendment, agreed to change tack after the government chief whip Sir George Young sent a message to his opposition counterparts that the Tory leadership was facing defeat.

The move meant that the amendment, tabled by the anti-gay marriage Tory, former children's minister Tim Loughton, was defeated by 375 to 70 votes, a majority of 305.

The decision by the Labour leadership, which has gone from supporting the amendment on civil partnerships to rejecting it within the space of 24 hours, means that the marriage (same-sex couples) bill will now experience a safer journey through parliament.

The government had warned earlier in the day that the Loughton amendment would have threatened the entire bill by adding £4bn to the costs and delaying its implementation. The costs would have come from increased pension survivor rates for new civil partners.

Labour sources said that the party, which had announced earlier in the day that it would abstain on the Loughton amendment after overnight warnings from the government about the threat to bill, denied that Miliband had embarked on a double U-turn.

One source said: "We had an eleventh hour appeal from the government that they did not have the numbers to defeat the Tim Loughton amendment. They made repeated approaches to us at ever increasing levels.

"Ed's overriding priority is to ensure that the bill gets on to the statute book. Ed and Yvette Cooper will therefore be voting against the Tim Loughton amendment. We expect a large number of MPs to join Ed and Yvette. Since there was a genuine threat to the bill Ed decided the best thing to do was to act in this way."

The appeal by Tory whips for Labour support to ensure the safety of the bill highlighted deep divisions in the Conservative party in the wake of claims that a senior member of his entourage described party activists as "swivel-eyed". Lord Feldman, the Tory co-chairman, denied making the remarks.

More than 100 Tory MPs planned to register their opposition to the marriage (same-sex couples) bill by voting in favour of a series of amendments to water down the measure. In the first vote of the evening, more than 150 MPs voted in favour of an amendment that would allow registrars to refuse to perform same-sex ceremonies.

Tory opponents of the bill were alarmed when Labour and the Tories embarked on negotiations during the day. The government agreed during the day to a Labour request to amend its own plans by launching an immediate review into extending civil partnerships to heterosexual couples.

Maria Miller, the equalities minister, agreed to the Labour request. But she suggested that the review could lead to the end of civil partnerships when she said the review will see "if there is a demand for [civil partnerships]".

The deal meant that the government amendment, altered by Labour, was approved by 391 to 57 votes, a majority of 334.

But Labour initially said that it would abstain on the Loughton amendment on the grounds that it agreed with it but did not want to risk the overall bill.

The leaders of all the main parties offered all their MPs, including ministers and shadow ministers, a free votes on the grounds that marriage is a "conscience" social issue in which the party whips have no official say. But the prime minister devoted government time to the gay marriage legislation in the belief that it would help reach out to centre ground voters who may feel uncomfortable about supporting a party whose leader voted in favour of the retention of section 28 as recently as ten years ago.

The divisions among Tories was highlighted when Sir Gerald Howarth, knighted on the advice of the prime minister last year when he sacked him as a defence minister, warned of an "aggressive homosexual community" during a clash with a member of Cameron's policy board. Howarth made the remarks when Margot James, a fellow Tory MP who is in a civil partnership and who was recently appointed to the new Conservative policy board, said that the equal marriage legislation would level the playing field after gay people suffered discrimination in the 1980s.

Howarth replied: "I warn you, and MPs on all sides of the house, that I fear that the playing field has not been levelled. I believe that the pendulum is now swinging so far the other way and there are plenty in the aggressive homosexual community who see this as but a stepping stone to something even further."