Economic migrants forced into destitution by a law forbidding them to work, rent property or use the NHS have been handed a lifeline after a “David and Goliath” battle in the court of appeal.

The case was brought by Kehinde, a seriously ill Nigerian woman, who couldn’t afford the medication she requires to stay alive after the Home Office triggered a terrorism-related paragraph of immigration law to try to get her to leave the country.

She had originally come to the UK in 2007 to study, but in 2016 – earning £38,000 a year – she applied for indefinite leave to remain. The Home Office, however, refused her application on the basis of a discrepancy in her 2010/2011 tax return.

Under paragraph 322(5) of the immigration rules, Kehinde (who prefers not to give her surname) immediately became ineligible for any UK visa. She was allowed to stay and fight her case but not to work or have full use of the NHS.

Unable to afford legal representation, Kehinde fought her own battle through the courts to persuade the Home Office to reinstate her right to work while her immigration status was being decided.

In their ruling on Tuesday, Lord Justice Irwin and Lord Justice Holroyde agreed that they were setting an important legal precedent that could be used by other applicants with health problems as serious as Kehinde’s own.

In their oral judgement, the judges told the Home Office it was wrong to deprive Kehinde of her access to essential services and said she could immediately return to her job as a technical manager in the food industry.

Kehinde said she had no choice but to stay in the UK and challenge the decision: those forced to leave under the terrorism-associated paragraph are highly unlikely to ever get a visa to visit or work anywhere else in the world.

But the stress, she said, triggered the serious health problems she suffers from: she has accelerated phase hypertension with a dangerously high blood pressure of 215/140 – compared with a healthy maximum level of 120/80 – and chronic kidney disease stage 3.

“My blood pressure is so high because I can’t afford the medication that keeps it at a healthy level,” she said. “I am still on nine different medications. The doctor said this is not normal for a person of my age. I have no doubt that it’s because of the stress I suffer over my immigration nightmare.

“I wrote to the Home Office on several occasions to allow me to get back to work so I can earn the money to buy my medications and feed myself, but they said no. My landlord has gone to court to seek a possession order as, until the ruling today, I couldn’t pay my rent,” she added.

Colin Yeo, a specialist immigration law barrister at Garden Court Chambers, said: “This is a very important and significant ruling … Every economic migrant in the UK lost these rights under the 2014 Immigration Act and this case opens the door to any of those migrants suffering serious health issues to take their case to court too.”

The 2014 Immigration Act, and the 2016 Act after it, have been key to the creation of the hostile environment that has devastated the lives of those who have chosen to make the UK their home.

The 2014 Act was the first to make life very difficult for people when they ceased to have leave to be in the UK. Access to legal appeals was severely restricted and, for those who lost that right – or failed in their initial appeal – access to employment, healthcare, housing, education, banking and other essential services was removed or restricted.

After Tuesday, however, the government could be forced to rewrite the law to reinstate protections ensuring immigrants retain the right to work, rent and access the NHS while they challenge Home Office decisions regarding their immigration status.

“Before this case, it wasn’t clear what the limit of the 2014 Act was,” said Yeo. “But now a limit has been set, there will be many more of these cases going to court. And if the Home Office has to keep fighting – and losing – these cases, it could well end with enough pressure being put on the government from the courts, and the Home Office itself, for the secretary of state to back down entirely and introduce new legislation through an act of parliament reinstating these rights for everyone affected by the ruling today.”

Kehinde said: “The Home Office has destroyed my life even though I have never received any benefits during the decade-plus I have lived here. Instead, I have always contributed to the system: in the five years before the Home Office stopped me working, I was paying more than £600 a month in tax and national insurance.”

A Home Office spokesperson said: “We are considering the interim order carefully and will respond in due course. It would be inappropriate to comment while the legal proceedings are ongoing.”