Media playback is unsupported on your device Media caption Many former South African miners are suffering from lung conditions

Mining companies have agreed a 5bn rand ($400m, £285m) compensation deal for tens of thousands of South African miners who contracted deadly lung diseases while working underground.

The miners contracted silicosis, an incurable lung disease caused by inhaling dust from gold-bearing rocks.

The dust lodges in the lungs, causing permanent scarring and can often lead to tuberculosis.

Almost all of the claimants in the case that dates back to 1965 were black.

The settlement is thought to be South Africa's biggest group legal action.

The mining companies include Harmony Gold, Gold Fields, African Rainbow Minerals, Sibanye-Stillwater, AngloGold Ashanti and Anglo American.

'Beneficial'

They have also set up a compensation fund worth almost 4bn rand to help affected miners or the families of those who died from the diseases.

Analysis: Milton Nkosi, BBC business correspondent in Johannesburg

Image copyright Getty Images

This agreement will bring closure to tens of thousands of miners right across the southern African region who suffered at the expense of big gold mine companies as far back as the mid-1960s.

The groups representing miners told me that they welcomed this legal action not just for the miners themselves but also for their destitute families who are surviving on meagre resources.

The question is whether other countries will follow South Africa's example of protecting the people on the ground - or in this case underground - with compensation, even if it has taken a long time to arrive.

The legal action was launched six years ago on behalf of miners suffering from silicosis, an incurable disease that causes shortness of breath, a persistent cough and chest pains, and also leaves sufferers highly susceptible to tuberculosis.

Carina du Toit, a lawyer with the Legal Resources Centre, one of the groups representing the miners, said the settlement was the product of "negotiation and compromise, but we believe this is a beneficial settlement".

Image copyright Reuters Image caption Sibanye-Stillwater is one of the companies that has settled with miners

The settlement avoids a lengthy and expensive court battle and means claimants will get compensation more quickly.

It still needs approval by the Johannesburg High Court before being implemented.

In 2013 Anglo American South Africa settled a compensation claim brought by 23 former gold miners in the country.

It was the first silicosis settlement in South Africa and paved the way for more cases.

Anglo American no longer owns any gold mines in the country.