The three ambassadors, the metroplitan police and the others who negotiated the release of 124 hostages held by the Hanafi Muslims last week relied heavily on the advice of psychiatrists and psychologists who specialize in defusing hostage situations.

"The last thing we wanted was that" Hanafi leader Hamaas Abdul Khaalis "should go off the deep end," said Pakistani Ambassador Sahabzada Yaqub-Khan.

It was the effort to avoid just such a result - and the potential "bloodbath" that could follow, as one insider put it - that controlled the negotiating strategy throughout the 38-hour siege at three Washington buildings.

Two professionals who have the reputation of being among the very best in such situations were working with the team from the early hours. They are Patrick Mulaney, a psychologist in the FBI's behavior science unit, and Dr. Steven Pieczenik, a psychiatrist with the State Department's task force on terrorism.

Mulaney had helped formulate the plan that resulted in the surrender last month of Anthony G. Kiritsis. For 62 hours, Kiritsis had held a shotgun wired to the neck of a mortgage company executive in Indianapolis. Mulaney predicted within the hour when Kiritsis would give up.

Pieczenik was among the psychiatrists who advised the Federal Aviation Administration last September after a group of Croatian separatists seized a TWA jetliner and ordered it flown to Europe. All 92 hostages were freed wnharmed after 30 hours.

"The first thing we try to establish is some slement of mutual trust with the hostage-taker," said noe expert familiar with the techniques.

According to those familiar with the Hanafi situation, Deputy Police Chief Robert Rabe was invaluable in that respect in his conversations with Khaalis. It was Rabe who did most of telephoning to Khaalis before the ambassadors were brought into the picture.

"You're not going to get me to say who said what to whom," Rabe told a reporter. "I've got to protect my credibility."

But it is known that while Rabe was talking to Khaalis, who had established a command post on the eighth floor of the B'nai B'rith headquarters at 1640 Rhode Island Ave. NW, other officials were monitoring Khaalis' phone conversations.

Information from those calls gave the team added information it needed in evaluating the situation and considering tactics.

There were some things that could be done to "establish credibility" that did not cost very much. For example, one of Khaalis' most persistent demands was that the movie, "Mohammad> Messenger of God," not be shown Showings in New York were interrupted. The movie was not shown again until after the hostages were freed.

Another demand was that Khaalis receive the $750 in court costs that had resulted from his outburst at the trial of Black Muslims accused in the slayings of seven Khaalis family members in 1973. The money was sent to Khaalis' residence on 16th Street NW.

There are also the "impossible demands," as one specialist called them. Khaalis asked several times that the men convicted of those 1973 slayings and now in federal prisons be delivered to him.

Another time, he asked that Mayor Walter Washington be traded for some hostages.

Such demands were ignored, or talked around, in hopes that Khaalis would realize they were unobtainable.

But as the hours wore on, there was a lessening of tension. It has become a belief in hostage situations that if nobody is killed in the early hours, chances for successful negotiations are greatly enhanced.

"Every time we could concede to a wish," one negotiator said, "he'd come back and concede. He became very attentive to the hostages at a certain point. That's why some of the hostages were released. It got to the point where we could tell him to go check on the safety of the hostages and he would do it."

Through the long hours of talking, the negotiators were building a file on their man, seeking a key that would make possible a happy ending.

At the same time, they were looking to avoid words> phrases or incidents that would enrage Khaalis. One danger in such a situation, experts said, is the uncontrolled telephone call from the outside: a reporter who unwittingly asks the wrong question, a family member who delivers bad news.

The ambassadors - Ashraf Ghorbal of Egypt and Ardeshir Zahedi of Iran in addition to Yaqub-Khan - benefited from the information collected by the experts. Between phone calls they made to Khaalis, they planned what verses of the Koran to use and how to use them.

A central conclusion in dealing with Khaalis, according to several close to the negotiations, was to recognize that he was still suffering from "a very deep personal hurt" in the murders of his family members.

By the time the siege had run its course, enormous radio, television and newspaper coverage had told the world of his grief. But such coverage is a double-edged sword. Law enforcement officers and others have often suggested that massive publicity only breeds repeat performances.

That question aside, Khaalis "felt his protest had been made," Ambassador Yaqub-Khan said. "He felt the world knew that he had been dealt with unjustly."

Then it became a matter of finding a way to free the hostages and leave Khaalis with some dignity, according to others who were there. It was after the face-to-face negotiating session at B'nal B'rith concluded that the nobond pre-trial release was agreed upon.