While endorsing the agreement the Carter administration made with Iran as necessary to win freedom for the 52 American hostages, outgoing U.S. Ambassador Ulrich Haynes said today that the deal sets "a very dangerous precedent" that could encourage more international kidnaping of diplomats.

Haynes, member of the U.S. team that negotiated the agreement here, said it would probably tie U.S. courts in knots for years over the right of the U.S. government to abrogate American laws in a treaty with a foreign government.

He, nevertheless, stressed that the accord was worth it since it brought the hostages back home and recalled that President Reagan had publicly pledged to honor it.

The ambassador, a Carter administration political appointee who is leaving diplomacy to return to private life, said he thought it was a question of "national honor" for the United States to try to abide by the agreement. But, he said, "Thank God I don't have to speak for the Reagan administration."

Questioned about whether he was jumping aboard the bandwagon of morning-after expressions of doubt that seems to have hit the new administration, he said in a separate telephone conversation that he does not consider himself on opportunist since he has already submitted his resignation.

Haynes made most of his remarks in a briefing at the U.S. Embassy residence here. The 49-year-old envoy has been here since mid-1977. He has served as a diplomat before, mostly on the staff of the National Security Council in the 1960s. But he is now planning to return to a high post with the Cummins Engine Co., an Indiana-based international exporter of heavy-duty diesel engines.

"I have nothing but a feeling of satisfaction tempered with realism," Haynes said. "I know we set a dangerous precedent."

"Can the American government," he asked, "Guarantee to a foreign government that an American will not exercise his right as a citizen to use the courts for redress of his grievances?"

He was referring, among other clauses, to the provisions of the Algiers agreement that the U.S. government will see to it that all legal claims by Americans against Iran will be dropped from the courts and submitted to a specially created international arbitration tribunal made up of equal numbers of Iranian, American and mutually acceptable third-country judges.

As a lawyer, Haynes said, he would realistically expect the accord to cause all sorts of complicated legal problems. Yet, he said, "we were overwhelmed with happiness when we saw those two girls and Bruce Laingen [the senior-ranking U.S. hostage] with their arms linked at the top of the stairs" early this morning upon arrival at the Algiers airport.

That moment justified the negotiations, he said. Nevertheless, he asked, "Is this the beginning of a whole new round" of diplomatic hostage-taking? "I just hope it doesn't set off a new chain."

Speaking for himself, he said: "I'm leaving the diplomatic career with a sense of relief that I don't have to worry every time I send my children to school, my wife goes shopping or I walk over to the chancery. This has become one hell of a profession."

There is the same dilemma over agreeing to negotiate with skyjackers or political terrorists, he said. "We're just in a new era."

Haynes seemed to imply that chief U.S. negotiator Warren Christopher, who was his fulltime house guest during the last two weeks of intensive negotiations, shares at least some of the same misgivings.

Calling the accord "miraculous" -- given all the technical difficulties in working out such a complex arrangement through intermediaries working with documents in French, English and Persian -- Haynes indicated his belief that the bargain we sealed when the Iranian government decided the time was right. He recalled that the Iranians had publicly admitted they were using the hostage issue to affect the outcome of U.S. elections. So, he said, he saw no reason why they should not have continued through the transition to the Reagan administration.

Challenging the good will of the Iranian government, Haynes, nonetheless, refused to discuss the details of the hitches that had cropped up in the talks. This might prove embarrassing to Algeria, he said.

Haynes said he was especially impressed by the "remarkable self-control" of the hostages when they reached freedom here. "We Americans," he said, "are not a bunch of huggers and kissers. But when the first bunch came down that ramp, there was hugging and kissing all around. But no one lost his control. No one broke down or started sobbing uncontrollably."

Haynes said he spoke to about 30 of the 52 freed Americans and asked them all the same question: "Did you ever lose hope?" They all answered to the effect, he said, that they had "absolute faith that everyone at home was trying his damndest to get us freed."

The most common question that the returnees asked their American greeters, the ambassador said, was "How do I look?" -- indicating concern that their appearances might have changed in ways troubling to others.

Another frequent type of question, Haynes said, was what he called "Rose Bowl-type questions." Five of the former hostages are graduates of the University of Michigan, winner of the last Rose Bowl Game.

The ambassador said he would rather not talk about what they had to say about their treatment in Iran. But, he said, many of them expressed great appreciation for the sensitivity with which they were treated by the Algerian crew of the plane that flew them to freedom, especially the touch of serving them champagne aboard the plane of an Islamic country whose religious traditions are against the drinking of alcohol.

The six Algerian doctors who were flown in to certify that the hostages were being returned in good health have turned over the results of their medical examinations to the U.S. Air Force hospital in Wiesbaden, West Germany, where the returnees were taken early this morning for several days of decompression under U.S. medical observation. One of the Algerian doctors was a psychiatrist, Haynes said.