As TWA Flight 847 hopscotched across the Mediterrean this weekend on the command of extremist Shiite Moslems a little-known Algerian envoy here emerged as one of the world drama's pivotal players.

Mohamed Sahnoun, Algeria's ambassador to the United States, sat in his embassy yesterday, facing another day marked by intense negotiations, another night of phone vigils, and countless press interviews. It has been like this, he says, ever since he was informed Friday that the hijackers were heading for Algeria from Beirut.

"We are in this because of the passengers," he said. "Not to please the American government. We are not very keen on having the plane land in Algeria, but we did not want to shrug off our humanitarian responsibilities."

A career diplomat who has served in a variety of plum ambassadorial assignments including West Germany, France and the United Nations, Sahnoun for the past two days was the primary intermediary between the United States and Algeria while the TWA plane was in Algiers.

"Essentially my role has been to inform my government of the American position," he said, "whether it is the official position explained to me by the State Department or the position in the public opinion, and to tell them the elements that can be used in discussions with the hijackers, any elements that can be used to persuade the hijackers to release the passengers."

Sahnoun said he hasn't slept since Friday. He stayed awake through that first night waiting for word that the plane had landed in his country, and again through Saturday night, waiting for it to depart. In the hours between, he met with Secretary of State George Shultz, spoke with TWA officials to ascertain the status of the passengers, and offered Algerian negotiators some counsel on how to cajole the hijackers.

By yesterday, the hijackers had released 87 passengers in Algiers, due to the efforts of the country and the International Red Cross. The plane then flew back to Beirut for the third time.

"I think the release is very much due to the ability of our negotiators who have used all sorts of arguments -- psychological, moral, religious, political -- so that they secure the release of those passengers," he said. "It has been very difficult."

Sahnoun would not elaborate on what specifics he recommended to his government.

"I can't tell you that; you don't know what will happen," he said. "They might go back to Algeria. These things come out and they can be counterproductive.

"These are very delicate negotiations. A lot of psychology has to be used. I have to be extremely careful. What is said is always relayed by air or radio broadcasts and the hijackers listen to it. They might toughen their position."

Making this round of high-stakes international intrigue that much more difficult for the ambassador is the fact that he is in the middle of the annual Islamic ritual Ramadan, which involves total fasting each day until nightfall.

"You get exhausted," he said. "I have to take a lot of vitamins. You get headaches. You get tense. You go to a television station and they offer you a cup of coffee and you haven't slept and the first reaction is to take it. But then you realize -- I can't drink that. But in some ways it helps. You find yourself much lighter with the work you have to do. You do not feel heavy with a big lunch."

At 54, Sahnoun is known to be one of the more highly regarded Arab diplomats serving here, with much experience in Third World diplomacy.

Although he is considered rather low-profile by Washington diplomatic standards, rarely seen on the embassy social circuit, he made a name for himself here as a graduate student at New York University in the late '50s when he emerged as a spokesman for his country's national liberation efforts. Algeria was liberated from France in 1962.

He is the father of two teen-agers, who are in school in Algeria. He has been the envoy here since September.

This is not the first time Algeria has played a crucial role in an American hostage situation. In late 1980, Islamic revolutionaries holding 52 hostages in Tehran accepted Algeria as a suitable intermediary in negotiations with the United States. In the end, it was Algeria that worked out the release of the hostages, as well as an agreement on claims filed by Iran and the United States.

"We have acquired some experience with the release of the Iranian hostages," said Sahnoun, who was ambassador to France at the time and said he had a small role in those negotiations. "We were instrumental in that. And somehow, we have gotten some lessons from it. In a way, we are in better position than others to be the negotiators for this release."

Asked yesterday afternoon at 2 if he was heading back to the residence to sleep now that the plane was out of his jurisdiction, the ambassador looked surprised.

"Oh, no, I cannot sleep," he said. "Now we hear the plane might go back again to Algeria. Now, I just wait."