WITH THE ARMY now back in the barracks, Ayatollah Khomeini, in command of a great popular movement, is the clear victor over the government appointed by the shah. He has begun to set up an "Islamic republic" in Iran, whatever that may turn out to be. It is a true revolution, ending a period now widely seen as wicked and reactionary, catching up millions of people heretofore excluded from the political process, looking at once backward into the core of the Iranian culture and forward to the promise of a new national life. It is a time of exultation for those who identify with the ayatollah, and a time of uncertainty, too.

If Americans are to be honest with themselves, they cannot ignore that for 25 years they respected the shah for his modernization policies and profited from his cooperation in the economic and strategic spheres. Let us not pretend now that we didn't know the bad as well as the good -- that he ruled harshly and had strategic fantasies, but was a useful and reliable ally who could be counted on to advance American interests, indefinitely.Successive administrations bet heavily on him, getting more from him perhaps than they had any right to expect.

Still, Jimmy Carter was right yesterday to emphasize the continuity of the American interest in good relations with Iran, regardless of the regime. It is difficult -- and silly -- to expect a restoration of the sort of ties the United States had with the shah. Life in and around the "Persian Gulf" will not be so easy for the United States. But this country's three bedrock interests -- after the protection of its nationals -- still obtain.

The first interest is to buy oil. The second is to maintain access for diplomats, businessmen, travelers and so forth. The third is to have Iran stay out of the Soviet orbit. While Iran's reborn nationalism is in its current intense stage, it may not be easy to work out cooperation. But surely it is in Iran's interest to do so just as soon as it can establish order and start settling the new regime down.

Because the event took place on his watch, Jimmy Carter faces a long period in which he will be called upon to explain the "loss." The left will claim that he was insufficiently attentive to popular currents, the right that he failed to give ample backing to the shah. We happen to think that the seeds of the shah's disaster were sown long before he got to the White House, and that the shah's dynasty was never Jimmy Carter's to lose; accordingly, the "loss" cannot fairly be pinned to him. In any event, his best answer lies in the effort he now is making to build the best relationship he can with the new Iran.