JOHANNESBURG, AUG. 30 -- The National Union of Mineworkers, faced with the mass dismissal of thousands of its members, ended its three-week-old strike at South Africa's gold and coal mines today, accepting a management offer of improved benefits but winning no further increases in pay.

Cyril Ramaphosa, the mineworkers' general secretary, insisted that the union had not lost what both it and the major mining companies had seen as a crucial test of strength between black labor and white capital -- a battle that would have a broad political impact.

"We have not won all the demands we sought to win," Ramaphosa told a press conference, "but the Chamber of Mines has not . . . taught us the lesson they thought they would. We have emerged a lot stronger than we were.

"There is a stalemate in the mining industry at present -- they have not won, and we have not lost -- but they have helped the union lay a strong foundation for further and significant victories in the future."

The union accepted the wage increases -- 15 percent to 23 percent -- that management imposed two months ago when it refused further discussion of worker demands for 30 percent across the board. The average miner now earns about $285 a month, plus food and lodging, according to company figures.

The union also accepted company proposals for increased vacation pay and higher death benefits. It had rejected these as inadequate only last week, when it decided to continue what already had become the nation's costliest work stoppage.

The strikers began returning to work late today on the overnight shifts, but company and union officials said that it would probably take more than a week to bring back all the workers and resume full production.

Ramaphosa, explaining the union's abrupt reversal in its position, said that mineworkers' leaders and members had "reassessed the balance of forces" as tens of thousands of workers were fired late last week with uncertain prospects of being reemployed after an eventual settlement and the consequent weakening of the union.

It was unclear how many of the fired workers the mining companies would reemploy.

The focus had shifted, union officials acknowledged, from winning a larger pay increase and forcing the mining companies to back down to emerging with what Ramaphosa today called "an organizational victory" that would allow the mineworkers to renew their battle for higher wages next year from a position of strength.

Calling the settlement "a tactical move sideways," Ramaphosa said, "This was a dress rehearsal for further action -- 1988 has already been set by our members as the year when the National Union of Mineworkers is going to move to win more significant gains."

The union claimed that, at the strike's peak, more than 340,000 of the 600,000 black miners were out at 44 gold and coal mines. The South African Chamber of Mines, which represents the six major mining companies, has maintained that no more than 240,000 miners participated, but has acknowledged that the strikers shut down about a third of the country's 100-plus gold and coal mines.

"The union has learned that the industry is capable of setting the limits, sticking by them and showing a lot of determination in the process," Naas Steenkamp, president of the chamber, said after four hours of talks with the union today. "Likewise, I think the industry has learned that the union is under extremely capable leadership, that the union is determined and that it can be extraordinarily skilled in the negotiating process."

Bobby Godsell, industrial relations director of Anglo American Corp., the company hit hardest by the strike, welcomed the settlement and committed the company to "rebuilding relations between managers, workers, ourselves and the union as well as between black and white people in our industry."

Nine miners were killed in the course of the strike. Most of them died in clashes with mine security guards, but three apparently were killed by fellow workers angered by their refusal to join the strike. More than 500 were injured in clashes with police and security guards, and about 400 were arrested, including 78 on charges of attempting to kill strike breakers and endangering state security.

Godsell said the mining companies are not "under any illusions about the power, strength and effectiveness of the National Union of Mineworkers, its leadership and its membership."

He went on, "To take very large numbers of people out on strike and to keep them out for three weeks is a real achievement of a kind. But we would be looking for ways to exercise our respective strength and power that do less permanent damage to the lives of people."

Anglo American fired at least 36,000 miners last week in an attempt to break the strike and said it was ready to dismiss at least 20,000 more. An associated company fired nearly 10,000 miners.

Godsell said that Anglo American, which has prided itself on being the most progressive employer in the mining industry, had agreed to rehire many of the miners, but he warned that several thousand jobs were abolished when two unprofitable mines were closed and when operations were reduced in others.