South African Foreign Minister Roelof F. Botha today lashed out against American critics of his government's racial segregation policies, saying their efforts to force U.S. companies to pull out of South Africa would harm this country's black majority and hinder peaceful reforms here.

At the same time, Botha held out the possibility that his government might respond positively to recent published remarks by jailed black nationalist leader Nelson Mandela offering a truce between his outlawed resistance movement and the government in return for meaningful talks on South Africa's future.

Botha singled out for criticism Sen. Edward M. Kennedy (D-Mass.), who advocated American corporate divestment of business interests here during his recent visit. Botha said politicians like Kennedy advocated "taking punitive action against the black people of this country to get at the Reagan administration." He predicted such a move, if successful, would encourage bloodshed.

His remarks came in an interview with The Washington Post and The Christian Science Monitor in which he also said his government was committed to observing last year's nonaggression pact with neighboring Mozambique -- known as the Nkomati Accords -- "in letter and spirit" and would act "decisively" against anyone using South African territory to aid rebels seeking to overthrow the Marxist government in Maputo.

Botha said his government was "concerned" about the growing movement in the United States for withdrawing investment in South Africa. He said such a move would prove most damaging to the 150,000 blacks who work for American companies here and "who you've put in a position to afford better housing, better training, whose children can look forward to a better future."

Botha assessed the Reagan administration's policy of "constructive engagement" toward South Africa as a greater success than the tougher approach of the Jimmy Carter years, contending the Reagan policy had aided black-ruled states in the region more than it had South Africa. But he also distanced South Africa from Reagan.

"I believe the present administration is doing what it does in southern Africa first and foremost in the interests of the United States of America," he said. "In some areas our interests might coincide. In others they don't.

"We have no illusions that should the United States in its global views consider it necessary to take actions to the detriment of my country that you will not hesitate to do so."

He specifically criticized what he called "the impression which is being created by U.S. government spokesmen that they are all the time exerting pressure on South Africa." Such an image, he said, "is not helpful, to say the least."

He said President Pieter W. Botha's statement Friday promising limited rights to some of South Africa's urban blacks was made not to placate public opinion abroad but because "we believe it is in our interests."

Botha called "a very delicate matter" an interview published in London last weekend with Mandela in which the jailed nationalist leader made his offer of talks. While stressing he was not commenting officially for his government, Botha said he believed that if Mandela denounced "violence as a means to achieve political objectives, . . . there would be at least a sympathetic consideration of the whole matter."

Mandela has served 20 years of a life sentence for treason and there has been growing domestic and international pressure on South Africa to release him.

Botha, a prime architect of the Nkomati Accords with Mozambique, said those who supported the rebel Mozambique National Resistance movement "are damaging South Africa's interests."

He was responding to allegations from Mozambican officials that the rebels are still receiving arms and other supplies from private individuals or from elements inside the South African military. Such aid would violate the key section of the accords, which pledges each country to withdraw all support from the other's foes and to prevent attacks against the other from its soil.

Botha said it was possible insurgents were receiving aid from people inside South Africa. "We have long borders, rugged terrain, scarcely populated regions," he said. But he said Mozambique had been unable to provide evidence of incursions that would enable his government to move against violators.

Botha said he has made personal efforts to make Nkomati succeed, including an attempt in October to mediate a cease-fire between Mozambique and the rebels and a visit last month to unidentified African states where he sought assurances that they were not providing arms to the rebels. That trip followed allegations by Mozambican officials that aircraft from Malawi, Tanzania, Somalia and the Comoros Islands were being used to resupply the insurgents in Mozambique, according to Botha, who said the presidents of the countries he visited denied the charges.

Some analysts said they believe that while Botha and other South African diplomats are sincere in seeking to enforce Nkomati, elements in the South African military who were the Mozambican rebels' chief source of support for several years, are undermining the policy in an effort to keep pressure on Mozambique's government for further concessions. Botha denied there was a split between diplomatic and military officials on the issue.

He said his efforts to mediate between Maputo and the rebels so far had not succeeded and he indicated that the rebels had hardened their negotiating position when he met here recently with Evo Fernandes, general secretary of the Mozambique National Resistance. He said he told the rebels that "if they continue with this, they will inherit destruction and that I foresee no end to the bloodshed and conflict."

But Botha, who has staked much of his prestige on the success of Nkomati, said he would continue to push for a settlement.