Striking platinum miners in South Africa have accepted an agreement with Lonmin and plan to return to work on Thursday, all but ending five weeks of acrimony, bloodshed and tragedy.

The police massacre of 34 protesting mineworkers at Marikana last month was the worst display of state violence in the country's post-apartheid history. In all 45 people died during the bitter industrial action. Unrest spread to other mines, threatening the backbone of South Africa's economy.

On Tuesday strikers gathered near the Marikana mine 60 miles north-west of Johannesburg cheered when they were informed of London-listed Lonmin's final offer. It includes a 22% pay increase for rock drillers – taking their pay to just over 11,000 rand (£825) a month – and a one-off payment of 2,000 rand (£150) to help cover nearly six weeks of not receiving wages while on strike, Bishop Joe Seoka, a member of the negotiating team, told Associated Press.

About 5,000 strikers gathered in a stadium to hear the deal, and cheered and sang when they finally accepted the offer, described as record-breaking. They formed a line and danced out of the stadium. "You have won as workers," Seoka told the crowd. He said there would be further negotiations in October when they could discuss a further increase.

One worker held up a hand with the phrase "Mission Accomplished" written in black ink.

Lonmin confirmed that a wage deal had been signed, officially ending the strike.

Opposition parties welcomed the settlement. Sej Motau, shadow minister of labour for the Democratic Alliance, said: "We hope that this brings the necessary stability to the situation at Marikana, for appropriate humanitarian assistance to be provided to the families of Marikana victims and for unencumbered reflection on the majoritarian labour regime that has contributed to the tragedy.

"The DA remains convinced that the events at Marikana could have been prevented through a more equitable labour regime, with a better prepared police service and in a minerals sector in which policies serve a broader range of stakeholders. We will be using our position in parliament to push for appropriate policy reforms.

"We hope that the Marikana workers will be allowed to return to work without fear for their safety."

The deadly strike has shaken Lonmin, mining and the whole of South Africa, triggering a wide ranging debate about the role of mining companies and labour unions, persistent police brutality and impatience at the governing African National Congress's lack of progress in arresting inequality after 18 years. It reportedly cost the country more than 4.5bn rand.

The ferocity of the government's crackdown, and allegations that police tortured detained mineworkers, has been compared with the era of racial apartheid. Last weekend soldiers supported police as they seized weapons and dispersed some protesting workers with teargas and rubber bullets.

Simon Scott, the company's acting chief executive, said: "These have been difficult and tragic weeks for everyone involved with the company, the communities living around our operations and the South African nation as a whole.

"Tonight's agreement and the subsequent return to work is only one step in a long and difficult process which lies ahead for everyone who has been affected by the events at Marikana, but it is essential in helping secure the futures of our tens of thousands of employees and all those who rely on Lonmin in the region."

The Lonmin workers were the first to strike and in recent weeks seven other mines had work stoppages. Partially led by the Association of Mineworkers and Construction Union (AMCU), the strikes have swept across the platinum belt, home to nearly 80% of the world's reserves. AMCU is challenging the dominance of the National Union of Mineworkers (NUM), whose leaders have grown rich and powerful from an alliance with the ANC, which has relied on organised labour for votes.

The work stoppages reportedly cost the country more than 4.5bn rand (£335m). They hit the rand currency, raised insurance against default on South African debt and spooked some foreign investors into selling shares in mining companies.

In another sign that weeks of labour unrest could be ending, Anglo American Platinum said it had resumed its operations in the strike-hit Rustenburg area.

"Anglo American Platinum Limited (Amplats) confirms that all of its Rustenburg operations have resumed, effective from today's morning shift," the company said.

On the news of the Marikana agreement, the spot platinum price fell 2% to a session low at $1,627.49/oz and the rand firmed against the dollar.

The conflict in the mining sector had also damaged president Jacob Zuma and the ANC, whose response was seen as slow and ineffective. They face accusations that they had neglected poor workers and sided with wealthy business owners.

On Tuesday Julius Malema, an ANC rebel who calls for the nationalisation of mines, criticised Zuma for sending the army to Marikana in recent days as if was under an "undeclared state of emergency". Malema added: "Never in the history of the ANC has a sitting president presided over such chaos and division in the ANC and the country."