Tens of thousands of gold miners in South Africa who contracted fatal illnesses while working underground have won a compensation deal from their former employers that could be worth more than £280m.

A high court in Johannesburg, the country’s commercial capital, approved the agreement on Friday, concluding a long legal battle and years of negotiations.

“It’s been a long road … very challenging. But I think we’ve got a good settlement. It’s a huge relief,” said Richard Spoor, a leading lawyer on the case.

A key decision in 2016 by a South African judge allowed lawyers to launch the unprecedented class action on behalf of miners with silicosis, caused by inhaling silica dust from gold-bearing rocks. The agreement has been hailed as “historic”.

Up to 500,000 former mineworkers in South Africa and neighbouring countries are thought to have the disease after spending years drilling in narrow tunnels. Many have been unemployed since being laid off by mining companies as long ago as 1965.

Compensation will vary from case to case, but could be more than £28,000, though many will receive much less.

“We are very happy, very happy. We are just poor people and this will help us somehow, somewhere,” said Hendrik Mokoena, a 57-year-old former gold miner who has the incurable disease.

Representatives of the miners said the dangers from silica-laden dust were raised a century ago as the South African mining boom got under way. A solution – blowing vast quantities of chilled air through the mines and masks – was also known, but began to be implemented only recently.

The disease causes shortness of breath, a persistent cough and chest pains, and makes people vulnerable to tuberculosis.

Spoor said negotiations had been made more challenging by the decline of the gold mining industry. An additional reason for urgency was the age and infirmity of the miners with silicosis.

“We’ve done the best we can, but I’m always anxious about not holding out long enough – we’ve already lost half of the potential claimants,” he said.

South Africa was the world’s top gold producer for more than a century, but has fallen to eighth place behind Peru over the past decade. The country is thought to be the source for about a third of all the precious metal in circulation.

Miners played a central role in the struggle against apartheid and the industry has long been a flashpoint. In 2012, in one of the most traumatic episodes in recent South African history, 34 miners who were calling for higher wages were shot dead by police outside a platinum mine near Johannesburg.

Former miners with silicosis and other diseases have long been entitled to limited compensation from a government-administered fund, to which some mining companies make a contribution. However, the sums are limited, there is a huge backlog of claims, and relatives of miners who have already died received nothing.

It takes about 10 years for miners to develop silicosis from constantly inhaling dust, according to doctors. This delay means that the extent of the problem is still unknown. Many of those affected by the disease are from remote rural areas, sometimes in neighbouring countries, and die without understanding the cause of their suffering.