Under the current law, religious groups can restrict jobs to believers and refuse to hire people whose private conduct is inconsistent with their teaching.
The Government had been proposing to water down these restrictions in Harriet Harman’s Equality Bill, which was being debated in the House of Lords yesterday.
However, the key amendments to change the law were thrown out by peers in a vote by 216 to 178 in a humiliating defeat for Miss Harman.
Miss Harman can try to force the measure through the Commons – and risk losing the whole Bill because of the short amount of time left in this Parliament.
The other option would be to drop the proposal and leave the UK at odds with an existing EU directive.
Last night secular campaigners said they would be complaining to the European Commission if the measure was dropped.
During a debate in the Lords, Baroness O'Cathain, who led the rebels, said: organisations should be free to choose their staff on whether they share those beliefs.
“How would a rape crisis centre operate if it was forced to employ male counsellors. This is the state trying to tell people who the can and can’t employ.”
She added that a Government minister had already given warning that the plans would lead to legal battles between churches and atheists, insisting that both sides “need to be lining up (their lawyers) by now.”
John Sentamu, the Archbishop of York, added: “Where are the examples of actual abuses that have caused difficulties?
“Where are the court rulings that have shown that the law is defective? If it ain’t broke, why fix it?
“The truth is that there are none because the status quo has been working perfectly satisfactorily.”
In reply Baroness Royall of Blaisdon, Leader of the House of Lords, insisted it was “not the Government’s intention to narrow the scope of the Bill”.
The Equality Bill is an attempt by ministers to consolidate existing anti-discrimination legislation into a single Act of Parliament.
Baroness Sayeeda Warsi, the Conservatives’ shadow minister for Community Cohesion, hailed the vote as a “victory for common sense”.
She said: “We delivered a blow against the governments attempt to narrow the definition of ‘employment’ for the purposes of religion.
"The Church of England, the Catholic Church and leaders of other faiths have all campaigned together in a true spirit of Community Cohesion to protect an important religious freedom."
Mike Judge, a spokesman for the Christian Institute, said: “We are delighted that the House of Lords has voted to protect freedom of association for churches.
“It is a shame that the Government didn’t listen to churches earlier. It’s almost as if they don’t care about Christians.”
But Keith Porteous Wood, executive director of the National Secular Society, said: “The Government has faced a humiliating defeat at the hands of religious agitation in the Lords.
“The National Secular Society will once more complain to the European Commission. It is now quite likely the Government will be prosecuted in the European Court of Justice.”
Lady Butler-Sloss, one of Britain's longest serving senior judges, told peers the Bill would restrict "the rights of religious groups to work with those of the same views and same religious convictions and it will, if passed, create the confusion it seeks to avoid."
Labour peer Lord Davies added: "My support for my Government is second only to my Christian view.
"My view is that the standards and morals of the Christian church makes this country a much better place and I shall always oppose any measures that seek to marginalise the Christian Church."