BEIRUT, Lebanon (AP) _ Gunmen from the radical Islamic Hezbollah group were guarding 40 American hostages Sunday in different locations around Beirut while Shiite Moslem Amal militiamen acted as ''observers,'' a high-ranking Amal official said.

Amal took charge of negotiations for the release of the captives June 16. Their principal demand is the freedom of 766 Lebanese prisoners captured by the Israeli army during its three-year occupation of south Lebanon.

The official, who spoke on condition he not be identified, gave this account of the militia's part in the hostage drama.

Two days after the Boeing 727 was seized on an Athens-to-Rome flight by two members of the Hezbollah - Arabic for Party of God - the dominant Amal militia said it wanted to transfer the remaining 37 passenges to secret locations in Moslem west Beirut, the official said.

When the Hezbollah protested, saying it wanted to maintain control of the hostages, the Amal agreed to form joint teams to guard them.

The three-member American crew remained aboard the plane with the hijackers and several of their Hezbollah comrades, he said.

''Our offer was to keep them secure. We have some unarmed people from Amal with the kidnappers,'' the official said. ''There are Amal (men) on the plane as observers to make sure they (the three hostage crew members) are safe and they are treated properly.''

The official said the more moderate Amal militiamen sometimes had problems with the Hezbollah. ''For instance, when we asked them to release a sick man - Robert Peel - we had a hard time to make them accept. They said if we let one go, then others would want to go too,'' the Amal official said.

Peel was released and flown home last week.

The official said there are 17 different Hezbollah groups, some of them financed and directed by Libya and others by the Palestine Liberation Organization, and that they receive their money through the Iranian Embassy in Damascus, Syria.

But he said it was unclear which group hijacked the TWA plane.

The official said Amal had nothing to do with the hijacking and had no prior knowledge of it. ''We are against kidnappings,'' he said.

He described the hijackers as becoming desperate while flying between Beirut and Algiers, Algeria, the day after hijacking the jet.

''They felt really pessimistic. They did not want to give up,'' the Amal man said.

''We tried to mediate as Amal, to help the hostages and the kidnappers and make all their lives safe. Our first demand was that the lives of the crew and the hostages be secure. We asked them, 'What are your demands?'

''They said they were three. Firstly the freeing of prisoners in Atlit in Israel; secondly, freeing of the two prisoners in Spain ...; and thirdly, freeing the people jailed in Kuwait.''

Two Shiites are being tried in Madrid for an abortive attempt to assassinate a Libyan diplomat. Seventeen are held in Kuwait for the bombings of the U.S. and French embassies there in 1983.

''We told them the third condition is hard and we cannot deal with it, that too many people had been kidnapped because of this, too many countries interfered. They said OK then, there are two conditions,'' the official recalled.

About 10 American and French citizens have been kidnapped in the past 15 months in Lebanon. The radical Islamic Jihad terrorist group, often said to be composed of Hezbollah members, has claimed responsiblity for the abductions and demanded the release of those jailed in Kuwait.