The health secretary, Jeremy Hunt, has had his decision to reduce services at a major hospital declared unlawful and quashed by the high court.

There was loud clapping in court as a judge ruled that Hunt had acted outside his powers when he announced to parliament in January that casualty and maternity units at Lewisham hospital in south-east London would be downgraded.

Mr Justice Silber said the secretary of state had breached provisions of the National Health Services Act 2006.

The ruling is a major blow to the health secretary and a victory for the London borough of Lewisham and the Save Lewisham Hospital campaign, a community-based group made up of and supported by patients, community groups, GPs, hospital doctors, nurses and other health professionals.

Speaking to cheering supporters outside the court in central London, Dr Louise Irvine, a local GP and chair of the Save Lewisham Hospital campaign, said: "This is an incredible day. We are delighted for every single person who has supported the campaign and those who will now continue to benefit from this extraordinary hospital. The support from thousands of people in Lewisham is a very real demonstration of the 'big society'. David Cameron himself said there would be no 'top-down' approach to closures and we appreciate the court's decision, which should serve as a reminder to this government not to forget their promises and not to underestimate those who they seek to represent."

Irvine paid tribute to the campaign group 38 Degrees, which helped fund the legal challenge.

"We're delighted by the judgment and the support we've got from across the country, especially from 38 Degrees members who donated to make today's victory possible and helped give us the confidence to stand up to Jeremy Hunt in court."

David Babbs, executive director of 38 Degrees, said: "It's not everyday that ordinary people take a government to court and win. Thousands of 38 Degrees members donated to make this possible – it proves just how determined we all are to protect our NHS from Jeremy Hunt."

Elisabeth Laing QC, for Lewisham council, told the judge at a recent hearing at London's high court that Lewisham was a "very good hospital" and the range of health services provided there was "greatly valued by local people and by the council". If the changes were made, it would mean local people "will have to travel a long, long way further to get access to vital services", said Laing.

The proposed changes were part of a wider shakeup of services in the capital after the financial collapse of the neighbouring South London Healthcare NHS trust, which went into administration after it started losing more than £1m a week.

Hunt told MPs the changes would improve patient care in south London, saving up to 100 lives a year, but gave an undertaking not to implement them pending this latest legal challenge.

Following Wednesday's ruling Rosa Curling from the law firm Leigh Day, who represented the Save Lewisham Hospital group, said: "This is a tremendous victory for all the people of Lewisham and for the thousands who have campaigned for this well-run, successful hospital to remain open. This mobilisation of the public in support of Lewisham hospital has been extraordinary … Real questions must now be asked about the decisions being taken by this government in relation to healthcare."

She said Hunt cut services at Lewisham hospital because of financial difficulties faced by its neighbouring trust, South London Healthcare.

"These difficulties were caused by disastrous PFI contracts entered into by South London, which were costing £60m a year to service. The court found Jeremy Hunt had acted outside his powers by trying to make Lewisham pay for the financial problems of its neighbour," she said. "The secretary of state cannot respond to the financial difficulties caused by the Department of Health's damaging PFI policy by simply imposing cuts on NHS services from above. This judgment should serve as a warning to the government that, if they try to do this, local communities will fight back to ensure their healthcare services remain in place."

The judge gave the health secretary permission to appeal against his decision.

A Department of Health spokesman said it was disappointed by the decision: "This judgment applies to one aspect of a package of changes which we believe are in the best long-term interests of patients and the public across south-east London. As it stands, the South London Healthcare NHS trust has been running at a loss of about £1m a week – money that has to be diverted from frontline patient care. So of course we are disappointed by this decision. We need to consider the judgment carefully, and have obtained permission to appeal."

He said the government expected to continue with the other "elements of that package of changes", including the dissolution of the South London Healthcare NHS trust, planned for 1 October.

Mike Farrar, chief executive of the NHS Confederation, representing health service organisations, said: "The NHS cannot afford to lose time on securing safe and sustainable services for people. We need proper legitimate processes firstly to identify the right solutions and secondly to underpin consultations with the public.

"The government now needs to act quickly to get a better solution for healthcare in this part of London and a better process that commands public confidence to deliver it."