Government plans to close a loophole in mental health laws have been defeated in the House of Lords.
The changes are expected to affect some 14,000 people
Ministers want to change the Mental Health Bill to allow more people with severe personality disorders to be detained or forced to have treatment.
But peers introduced an extra safeguard to protect mentally ill people who were easily capable of making decisions.
The government said it would result in some patients going untreated, possibly harming themselves and others.
About 50 Labour MPs have already signalled their intention to oppose the bill, which would apply to England and Wales, when it returns to the Commons.
It would allow the enforced detention of people who are mentally ill, even if they have not committed any crime.
And it would strengthen powers, established in 1983, to ensure patients have therapy once they are released back into the community.
Supporters of the amendment, introduced by a cross-party alliance of peers, asked why cancer sufferers were allowed to refuse treatment, but not those with a mental illness, even if they were still able to take decisions.
Peers defeated the government by 225 votes to 119, a majority of 106.
Health Minister Lord Warner has said the aim of the Mental Health Bill is to protect the public and patients from harm.
Between 55 and 60 murders a year are committed by mentally ill patients.
But Labour peer Lord Bragg, president of mental health charity Mind, said the bill was rooted in "the stereotype that those suffering from severe mental health problems are likely to be threatening and dangerous."
The bill was promised in the Queen's Speech and comes after previous attempts to change the act were thwarted by opposition from campaigners and doctors.
The changes would affect about 14,000 of the 600,000 people who use mental health services each year.
The desire to change the law was largely driven by Michael Stone's 1998 conviction for the murders of Lin and Megan Russell.