South African President Pieter W. Botha said today that his government would not abandon its program of limited political change despite a swing to the right among whites voting in five parliamentary districts yesterday.

Botha's Nationalists, who have ruled the country without interruption since 1948, suffered a roughly 20-point loss in yesterday's by-election contests compared with the last general election in 1981. The reduced margin was widely attributed to growing anxiety among white voters over mounting economic troubles and 14 months of black political unrest that has continued despite a three-month-long state of emergency.

Botha, whose ruling National Party took four of the five formerly safe seats by a reduced margin and lost the fifth to an extreme right-wing party that preaches undiluted white supremacy, said in a statement that he would "take cognizance of the reasons why people voted the way they did."

But he said in a speech tonight to foreign journalists here that his government was committed to "urgent and incisive steps to broaden democracy," although he outlined no new departures from the basic pattern of white-minority control.

"There is no one in this country, or anyone anywhere else, who appreciates the need and urgency for reform better than members of this government," Botha said.

Jaap Marais, leader of the small Herstigte Nasionale, or Reconstituted National Party, which won its first parliamentary seat since it was formed in 1969, said the victory left "no doubt that there is a significant drift away from the National Party."

The winning Herstigte candidate, Louis Stofberg, who in the past has equated Botha's party with communism, said the result "heralds the resurrection of the Afrikaner nation as a free and independent unity." He was referring to the Afrikaner ethnic group that makes up 60 percent of South Africa's white minority.

Stofberg won a narrow victory in a blue-collar district that has been hit heavily by unemployment and was the scene of some of the earliest black unrest last year. It was the first time in 32 years that the Nationalists had lost a seat in the predominately Afrikaner Orange Free State, a conservative stronghold.

Also disturbing for the government were its reduced victory margins in the other four seats, in which its principal opposition was the Conservative Party, a splinter group formed in 1982 to oppose the government's grant of limited rights to South Africans of Asian or mixed-race origin.

One newspaper projected that Marais' party and the Conservatives together could win between 40 and 55 seats in the 178-seat all-white house in Parliament, where they now hold only 19. The next general election is likely to be in 1989.

But Botha declared in today's statement that the results do not show that his party is in political trouble. "Considering the difficult economic consequences of the recession, the drought conditions suffered by the country, as well as the present unrest, the government can express its satisfaction with the results of the by-elections," he said.

The two white parties to Botha's left also were hurt by yesterday's results. The Progressive Federal Party, the official parliamentary opposition, saw its vote total in an industrial district east of Johannesburg cut by more than half compared to 1981.

The shrinking New Republic Party, which holds only five seats in Parliament, won less than 10 percent of the vote in a district in its supposed stronghold of Natal Province. Its leaders are considering disbanding the party.

Progressive Federal Party leader Frederik van Zyl Slabbert expressed disappointment in the vote. But he said the real lesson of the by-election was that the government must make a stronger commitment to political reforms or face further erosion of support both from liberals who fear it is moving too slowly and from conservatives who fear any change at all.

"When it comes to reform, the government must learn that 'in for a penny, in for a pound' is the way to approach it," said Slabbert. "Half-hearted and ambiguous reform will lose it support to the left and to the right."

In his speech to foreign correspondents tonight, Botha cited recent allegations that unnamed foreign television crews had paid blacks to stage incidents for their cameras and he accused the press of holding an "animosity toward the South African people."

Botha did not announce new press restrictions, but other sources said that on Friday the government would announce restrictive accreditation rules for foreign reporters, who have been subjected to mounting official allegations of having contributed to South Africa's deteriorating image abroad.

More than 100 mixed-race students and teachers accused of joining in the unrest were arrested by police at a Cape Town high school today, according to local press reports. They joined at least 101 other persons who have been arrested in the area since the government extended its emergency decree there last Friday. Police have not confirmed the new arrests.

A regulation published today allows the law and order minister to extend, until the end of the emergency, periods of arrest "without notice . . . and without hearing . . . . " Previously, detainees could only be held 14 days unless the minister signed a written order extending their imprisonment.

Heavy rains throughout South Africa limited to a handful the number of reported new disturbances. Meanwhile, police released new statistics contending that political violence has taken 761 lives in the past year and resulted in at least $50 million in property damage. They said 504 persons were killed by government security forces, while 232 died at the hands of other blacks. Fourteen black policemen and a white soldier also have been killed.

Other sources, including the South African Institute for Race Relations, have put the death toll at more than 800 since September 1984.

Police said 1,920 private homes and 460 homes of black policemen had been destroyed in the unrest, while 615 schools had been damaged. Nearly 1,000 businesses, shops and other buildings had been destroyed, as had 3,300 buses, 3,140 private vehicles and 1,600 police vehicles.

The daily average number of deaths has more than doubled since the state of emergency was declared on July 21, according to the Institute for Race Relations. Nonetheless, a police spokesman said that there had been "a definite decrease" in the number of incidents since the emergency decree took effect.