They were challenging immigration rules which said that those who retired from the British Army before 1997 did not have an automatic right to stay.
Prominent supporter actress Joanna Lumley said it was a “chance to right a great wrong”. The government said it would now review all Gurkhas’ cases.
‘Debt of honour’
The regiment moved its main base from Hong Kong to the UK in 1997 and the government had argued that Gurkhas discharged before that date were unlikely to have strong residential ties with the UK.
That meant those who wanted to settle in the UK had to apply for British residence and could be refused and deported.
The judgement could affect some 2,000 former Gurkhas who retired before 1997.
The judge, Mr Justice Blake, said the Gurkhas’ long service, conspicuous acts of bravery and loyalty to the Crown all pointed to a “moral debt of honour” and gratitude felt by British people.
He ruled that instructions given by the Home Office to immigration officials were unlawful and needed urgent revision.
Lawyer Martin Howe said: “Today we have seen a tremendous and historic victory for the gallant Gurkha veterans of Nepal.
“This is a victory that restores honour and dignity to deserving soldiers who faithfully served in Her Majesty’s armed forces.
“It is a victory for common sense; a victory for fairness; and a victory for the British sense of what is right.”
The five ex-Gurkhas involved in the test case were L/Cpl Gyanendra Rai, Deo Prakash Limbu, Cpl Chakra Limbu, L/Cpl Birendra Shrestha and Bhim Gurung. Gita Mukhiya also took part on behalf her deceased husband.
Gurkhas have been part of the British Army for almost 200 years and are hand picked from a fiercely contested recruitment contest in Nepal to win the right to join.
They have seen combat all over the world, with 200,000 fighting in the two world wars.
Lumley, whose father served with the Gurkhas, was one of those leading the campaign.
Outside court, she said: “This day is more important than I can tell you because it gives our country the chance to right a great wrong and to wipe out a national shame that has stained us all.”
Lib Dem leader Nick Clegg said it was a “wonderful vindication” for those who had campaigned for a change in the law.
“We will honour our commitment to the Gurkhas by reviewing all cases by the end of the year” said Home Secretary Jacqui Smith
“I’ve always felt that if someone is prepared to die for this country, then they should have the right to live in this country,” he said.
“The key thing now is to look at the ruling in detail and to make sure that the government now translates that into action and doesn’t try and squirm out of it.”
Home Secretary Jacqui Smith said in a statement that the Home Office would revise its guidance surrounding the 1997 cut-off date.
“I have always been clear that where there is a compelling case, soldiers and their families should be considered for settlement,” she said.
“We will honour our commitment to the Gurkhas by reviewing all cases by the end of the year.”