SANTA CRUZ, Calif. (AP) _ University of California regents voted Friday to sell off $3.1 billion in stocks and bonds in companies doing business with South Africa.

The meeting room, filled with about 200 spectators, erupted in cheers when the vote was announced. About 100 student demonstrators who had organized class boycotts celebrated outside the campus building.

''Naturally, I'm very pleased with the outcome of the regents meeting today,'' said Gov. George Deukmejian, who proposed full divestment earlier this week in a major shift of his position. ''We have now set a new policy for the manner in which the funds of the university will be invested.''

The two-hour debate among the regents was often heated, with several expressing fears they could be held personally liable if the university's pension funds suffered loses. But Deukmejian, a regent because of his office, said he would introduce legislation to protect the board.

The vote was 13-9, with one abstaining.

The companies will be given a 12-month grace period and, beginning next July, the university will reduce its investments in firms and banks with South African ties by one-third. By 1990, the university will hold no investments in any firms operating in that nation.

UC will make no new investments in firms or banks doing business in South Africa. This will not apply, however, if the firm has decided not to expand its operations in South Africa.

An amendment was added to Deukmejian's resolution to broaden the definition of South Africa to include ''any territory under the administration, legitimate or illegitimate, of the Republic of South Africa; and the 'bantusans' or 'homelands' to which South African blacks are assigned on the basis of ethnic origin.''

Deukmejian's Democratic rival for governor in the November election, Los Angeles Mayor Tom Bradley, also attended the meeting to urge the regents to accept the governor's resolution.

He did not stay for the vote, and criticized Deukmejian's policy change as ''the most monumental flip-flop in the hisory of his administration.''

Deukmejian last year vetoed a bill that would have halted investments of state and university pension funds in those companies. He favored a case-by- case review that was adopted by the regents last year.

Deukmejian dismissed Bradley's comments as ''petty politics.''

In his address to the regents, Deukmejian said his recommendations last year regarding South Africa were appropriate because conditions in that country were different than they are today.

''Unfortunately, in the past year, we have seen conditions change in South Africa,'' he said, citing the declaration of a nationwide state of emergency.

After weeks of student protests and arrests last year, the regents adopted a policy that called for selling interests in firms that did not adhere to the Sullivan Principles, which call for equal employment practices for South African blacks.

Since then, UC has withdrawn $12.3 million in investments in one company, Eaton Corp. of Ohio. It also has suspended further investments in Nalco Chemical Co. until the firm improves its Sullivan rating.