In a move intended to improve relations with Iran's revolutionary government, the Carter administration has decided to replace William H. Sullivan, the U.S. ambassador who became closely identified with the shah of Iran during the shah's final days in power.

U.S. officials said yesterday that Sullivan, who was criticized by political opponents both in Iran and in previous posts in Southeast Asia as practicing "counterinsurgency diplomacy," will return to the United States early in april.

Officially, Sullivan will return "for consultations." But U.S. officials acknowledged privately yesterday that he will not return to his post in Tehran and that a new ambassador will be named after a short hiatus during which the embassy will be headed by a charge d'affaires.

Iranian spokesman have said publicly that replacing Sullivan was an essential first step in improving relations with the Carter administration, which backed the shah's regime until it collapsed in February. The main spokesman in Washington for Ayatollah Ruhollah Khomeini, Shahrar Rouhani, said last month that the administration should name "someone who is not a disgrace" to American policy.

Sullivan's controversial role in Iran was reflected in the erractic course both of the revolution and U.S. policy.

While Iranian revolutionaries were denouncing him, Sullivan reportedly had fallen from favor with the White House for not supporting the shah strenuously enough at the end of the year-long crisis that drove the monarch into exile.

In late December, shortly after U.S. officials said the career diplomat had begun to report that the shah would not be able to surmount the crisis and the United States should shift if policy, the White House dispatched Gen. Robert Huyser, deputy commander of NATO, to Iran without initially consulting Sullivan. Huyser reported directly to the Pentagon and White House during his month-long stay.

But State Department sources report that Sullivan, for most of the crisis, strongly backed the shah, whom he saw frequently.

It was not immediately clear what effect the recall would have on Sullivan's career. He has served as an ambassador in Laos during the Indochina war, as ambassador to the Philippines when President Ferdinand Marcos was whipping up anti-American feelings over U.S. military bases there and as assistant secretary of state handling the Vietnam peace negotiations.

He became a favorite of former secretary of state Henry A. Kissinger for his works in those posts. His appointment to Iran indicated that Secretary of State Cyrus R. Vance and President Carter were impressed with his abilities. According to one report, he was offered one of the department's top echelon jobs but turned it down in favor of the Iran posting, where he felt he could influence and carry out policy more directly.

U.S. officials declined to discuss the exact timing of Sullivan's return. Fears about the possibility that leftist groups might try to prevent him from leaving the country and about the safety of American in general have been growing in recent days as conditions have reportedly become more chaotic throughout Iran.

The administration disclosed Thursday that it had discouraged Shah Mohammad Reza Pahlavi from settling in the United States, in part because of concern about possible retaliation against the estimated 2,000 Americans living in Iran. The shah is repotedly moving from Morocco to Bahamas.

The administration's handling of Sullivan will be carefully scrutinized by members of Congress and others the administration is not likely to want to offend. The ambassador's defenders maintain that he is the victim of having been the last in a long line of American envoys sent to Iran to reaffirm daily Washington's unswerving faith in the shah.

Critics, however, say that the optimistic reporting that came from the embassy under Sullivan's signature misled Washington policymakers for much of the crisis and that his reported last-minute switch came much too late to be meaningful.

Asked about the recall of Sullivan, a ranking State Department official said yesterday that a change in the Tehran embassy would be logical in view of the grueling nature of the assigment recently and an "obvious determination by the United States to maintain a close working relationship with Iran."

Sullivan and 70 other staff members of the embassy were held hostage by leftist guerrillas for several hours in February before being rescued by militia forces loyal to Khomeini's government.

U.S. officials sid yesterday that Khomeini's strong opposition to the Egyptian-Israeli peace treaty that was signed under U.S. auspices in Washington this week was one of the factors in the increased concern about the safety of U.S. citizens in Iran.concern about the safety of U.S. citizens in Iran.