The government radio said today that the execution of four generals accused of "treason, mass murder and torture" during the reign of the shah was "just the beginning" of a purge by revolutionary courts being set up under Iran's new Islamic government.

Government sources predicted that executions of more top military and political officials associated with repression and corruption under the rule of Shah Mohammad Reza Pahlavi would be decided soon. The Tehran newspaper Ettelaat said 20 such officials already have been condemned to death by an "extraordinary Islamic revolutionary court."

The first executions were carried out by firing squad last night on the roof of the headquarters of Islamic leader Ayatollah Ruhollah Khomeini, the government announced. Killed were Nematollah Nassiri, former head of the notorious secret police, SAVAK; Mehdi Rahimi, former police chief and martial law administrator; Manuchehr Khosrowdad, former commander of army aviation; and Reza Naji, former martial law administrator of the central Iranian city of Isfahan.

The executions followed by one hour a trial by a revolutionary court whose membership was not identified. Political sources said the executions apparently were intended to appease leftist guerrillas who have not yet had their fill of revolution and to warn against further resistance to the new government by loyalist troops and police.

"This is just the beginning," a senjor official of Khomeini's new provisional government told the state-run radio, now called "Voice of the Revolution."

The four generals were taken, blindfolded and with hands bound, to the roof of Khomeini's headquarters and sprayed with submachine-gun fire by four "soldiers of the revolution," a Khomeini aide said. He said former prime minister Amir Abbas Hoveyda, another official held by Khomeini's men, was in a room immediately below the executions.

Witnesses were quoted as saying Nassiri broke down and wept before he was shot, but that the others kept their composure.

Official sources quoted in Ettelaat said the executions were carried out "after the approval of Ayatollah Khomeini." The paper, which published pictures of the generals' bloody bodies according to tradition dating from the shah's time, said Khomeini's decision was based on a chapter of the Koran, the Moslem holy book, entitled, "They Are the Corrupt of the Earth."

After the executions were announced over a loudspeaker at Khomeini headquarters late last night, armed supporters of the ayatollah fired their weapons into the air in celebration.

The "revolutionary gestures" drew protests from forces that have supported Khomeini's opposition movement against the shah. Lawyers on the Iranian Human Rights Committee condemned the procedure and students planned a demonstration to protest the trial's secrecy, although not its results.

The seven-man Cabinet under Prime Minister Mehdi Bazargan has adopted enabling legislation to permit the government to seize all property of the shah and his family, try former ministers and "murderers of the people," confiscate their property and appoint more revolutionary courts for these purposes.

With the new government apparently as yet unable to maintain order and heavily armed revolutionaries controlling the capital, the American and other embassies were carrying out plans to evacute most of the estimated 14,000 foreign nationals remaining in Iran, about half of them Americans.

Several hundred Americans began assembling tonight at the battle-scarred U.S. Embassy compound in central Tehran, the scene of a two-hour attack Wednesday by leftist guerrillas. The embassy planned to bus the Americans to Tehran's Mehrabad Airport under protection of armed guards provided by Khomeini's headquarters.

The embassy estimated that about 6,000 Americans will be evacuated in commercial jumbo jets over the next several days at a rate of about 1,000 a day. The State Department has put the number of Americans remaining in Iran at about 7,000, including 940 government employes, most of them Defense Department or military personnel.

The nongovernment passengers, who are being limited to one suitcase and one piece of carry-on luggage each, must sign promissory notes to cover the cost of the travel, embassy officials said.

A privately arranged evacuation plane sent in by Pan American World Airways flew to Frankfurt, Germany, today with the first 152 to leave -- mostly Pan Am and Intercontinental Hotel employes, journalists and a few U.S. government employes. The plane later flew on to New York.

The British Embassy intends to evacuate nearly 900 of its 1,500 nationals' in Iran. France, West Germany and a number of other countries also are arranging evacuation flights for their citizens.

Except for occasional clashes and sporadic gunfire, Tehran seemed calm today. Sniper fire was reported in the vicinity of the U.S. Embassy, but there were no reports of anyone injured.

Three days of fighting in Tabriz finished in a government victory, the state radio said. It blamed the battles, in which several hundred persons were reported killed, on "counterrevolutionary SAVAK agents."

Other reports raised the possibility that leftist guerrillas such as those in Tehran had been resisting the authority of Khomeini's forces in the city, about 350 miles northwest of the capital.