Two pupils were shot dead and three others wounded today when police fired into a group of youths who threw stones at their passing vehicle in a nonwhite neighborhood in Cape Town, police said.

The deaths come amid a nationwide wave of student boycotts and labor unrest that has put the government and police on edge. It appears to be gaining momentum despite numerous arrests of pupils, teachers and community leaders in the last few days.

Although police refuse to say how many people they have detained under the country's extensive security laws, the latest detentions are clearly the largest number since the massive security crackdown of black leaders in October 1977.

The Johannesburg Star newspaper reported that 65 persons have been detained since Sunday under security laws. The South African Institute of Race Relations tabulates that since late March, 239 persons have been arrested, but an unknown number of those were subsequently released.

If anything, the arrests appear to have fueled the turmoil and the students' determination to confront the authorties. In Johannesburg, Colored and Indian students who had returned to classes last week resumed their boycott Tuesday, demanding the release of imprisoned colleagues. r

In Port Elizabeth, a traditional stronghold of black activism, police today arrested 275 black junior high school students who were marching into town protesting the detention of some students, police said. This is the boldest action by students in that town in more than two years. All marches and outdoor gatherings are prohibited throughout the country.

The shooting of the students, said by witnesses to be about 13 or 14 years old, occurred in a section of Cape Town restricted to Colored persons, the official designation for persons of mixed race under South Africa's apartheid laws.

The country's 2.5 million Colored population reacted with anger and shock to today's shootings, which are likely to inflame further the passions that led to the unrest.

"I was shocked," said Colored mechanic Petrus Present, who witnessed the incident. "One child was standing still, he was not running away. He was facing the police. I saw him fall to the ground."

Present, who said he has two teen-agers who are boycotting their classes, called the atmosphere in Elsies River Township, where the shootings occurred, "very tense."

Coloreds have been at the center of the present unrest, which began six weeks ago, when secondary and university students in the Cape Town area initiated a school boycott protesting the segregated education system. The boycott soon spread to Colored schools in other parts of the country and took on the character of a broader protest against apartheid, the system of racial segregation.

In the last two weeks numerous black schools have joined the boycott, particularly in Port Elizabeth, where 28 black schools are shut down. In the tiny black homeland of Qwa Qwa, 2,000 marching students were dispersed by police this week.

At the nonwhite University of Western Cape, students pelted the dean with eggs and tomatoes yesterday after he called police to break up a student meeting he had prohibited. Today, students were planning another meeting despite orders not to.

Meanwhile, the Committee of 81, an anonymous group of student leaders from each boycotting school in the Cape Town area, today condemned the detentions and what they termed the "Gestapo-like action of the police."

"This shows that the country is moving away from a democracy and becoming a totalitarian police state," the committee said.

In addition to the ferment at schools, black workers have begun to make increasingly more vocal demands. In Cape Town, more than 800 striking workers are at an impasse with the management of the area's slaughterhouses over a union recognition dispute. In Durban, nearly 6,000 textile workers were fired yesterday after striking over wage grievances. The workers say they do not accept being fired.

The government has begun to take a harder line toward the school boycotts. Police Minister Louis Le Grange Monday warned those who sought to turn the student unrest into a political confrontation with the government that "they will get what they are looking for."

In his statement on the deaths, Le Grange said today that the shootings followed "at least 50 cases" of vehicles being stoned in that area. The minister said about 400 youths were throwing stones today.

The police had strict orders to use firearms "only in the most extreme cases," Le Grande said. He did not say what action was to be taken against the four policemen involved.