The Court of Appeal has ruled Health Secretary Jeremy Hunt did not have power to implement cuts at Lewisham Hospital in south-east London.
During the summer, a High Court judge ruled Mr Hunt acted outside his powers when he decided the emergency and maternity units should be cut back.
The government turned to the Court of Appeal on Monday in an attempt to get the decision overruled.
Mr Hunt had previously claimed the move would improve patient care.
Following the ruling, Mr Hunt said: "I completely understand why the residents of Lewisham did not want any change in their A&E services, but my job as health secretary is to protect patients across south London - and doctors said these proposals would save lives.
"We are now looking at the law to make sure that at a time of great challenge the NHS is able to change and innovate when local doctors believe it is in the interests of patients."
At the High Court in July, Mr Justice Silber said Mr Hunt's decision was unlawful as he lacked power and breached the National Health Services Act 2006.
It was said the cuts would also mean local people having "to travel a long, long way further to get access to vital services".
Under government policy Mr Hunt had appointed a trust special administrator (TSA) to the South London Healthcare Trust, which went into administration after losing more than £1m a week.
To help ease the problem, the TSA recommended cuts at the Hospital.
At the Court of Appeal on Monday Rory Phillips QC, for the Health Secretary and the TSA, argued they had not acted outside their powers.
They challenged Mr Justice Silber's findings that the TSA was not entitled to recommend the changes and that Mr Hunt was not entitled to implement them.
Referring to the 2006 Act, Mr Phillips said its "wording, statutory context and purpose" should have led Mr Justice Silber "to conclude that they were entitled so to act, consistently with Parliament's evident intention".
The challenge against the government was brought by Save Lewisham Hospital and the London Borough of Lewisham.
Rosa Curling, who represented the campaign group, said: "We are absolutely delighted with the Court of Appeal's decision.
"This expensive waste of time for the government should serve as a wake up call that they cannot ride roughshod over the needs of the people.
"The decision to dismiss the appeal also reaffirms the need for judicial review, a legal process by which the unlawful decisions of public bodies, including the government, can be challenged by the public."
Andy Burnham, Labour's shadow health secretary, described the decision as a "humiliation" for Mr Hunt that "raises major questions about his judgment".
He said: "Instead of graciously accepting the first court ruling, he has squandered thousands of [pounds of] taxpayers' money trying to protect his own pride and defend the indefensible.
"Today, the secretary of state must accept this decision, apologise unreservedly to the people of Lewisham and give an unequivocal commitment that their A&E will not now be downgraded."
Mayor of Lewisham Sir Steve Bullock said: "This is a great result. I was confident of our case but I am still very relieved.
"This is another victory for each and every individual who signed a petition, who wrote to the secretary of state and who marched through the streets of Lewisham."
The decision was made by Lord Dyson, Lord Justice Sullivan and Lord Justice Underhill.