Iranian soldiers in Washington yesterday staged the first military coup in their nation's continuing revolution. In a bloodless takeover of the embassy on Massachusetts Avenue, Iranian military attaches toppled the charge d'affaires and restored a portrait of the shah to the embassy lobby.

The ousted diplomat asked for U.S. help and went into exile in Bethesda. The State Department fretted, said the Carter administration was powerless to intervene and let it be known "on background" that behind-the-scenes talks were under way. The embassy's press attache stoutly maintained through it all that nothing had happened.

To complete the Washington microcosm of the far more serious stresses and strains that have torn Iranian society apart in recent months, more militant Iranian diplomats issued a statement praising the return of Ayatollah Ruhollah Khomeine and supporting his "sacred revoltuion."

By the end of the day, the embassy was doing a better-than-usual job of truly reflecting conditions at home.

No one knew who was in charge, if anyone. No one knew what will come today, if anything. Orders came over a long-distance telephone line from a disputed ambassador traveling in Morocco with the shah.

The contending factions issued contradictory versions of the quiet takeover on Massachusetts Avenue. Speaking for the deposed diplomats, Ahmad Moshavegh-Zade gave this account:

The dispute was evidently triggered by a decision by Assad Homayoun, the embassy's charge d'affaires in the absence of Ambassador Ardeshir Zahedi, to remove portraits of Shah Mohammad Reza Pahlavi from the embassy walls because of Homayoun's concern that the portraits might be "shown disrespect" or be damaged now that the shah's rule appears to be over.

Apparently angered by this, Maj. Gen. Mokhateb Rafii and Capt. Cyrus Baharmast marched four or five security guards into the embassy late Tuesday evening, put the ceremonial portrait of the shah and his family back up in the lobby and took control of the embassy.

Yesterday: enter Homayoun. Security guards ask him and all others coming in what they want. Lively discussion between the diplomat and the general ensues. Exit Homayoun, followed by at least three other top diplomats. Scene shifts.

The four Iranians head immediately for the State Department, where they meet Henry Precht, the head of the Iranian desk, and demand that the United States restore law and order to the Iranian embassy.

Maintaining that Hamayoun is in charge of the embassy in Zahedi's absence, Moshavegh-Zade observes sadly, "This is unprecedented in my life."

Moshavegh-Zade stressed to a reporter later that the group had acted only "to protect our professional honor" and not for political reasons. He said the Carter administration, in the person of Precht, had promised to use "good offices" to settle the dispute, but he noted that the military were still entrenched at the embassy late yesterday.

The embassy press attache, Ali Akbar Tabatabai, spontaneously called The Washington Post yesterday to say that nothing had happened at the embassy all day.

But when questioned about reports of the military takeover, he conceded that a dispute was in progress because Homayoun, acting in defiance of Zahedi's instructions, had asked the military commanders to turn over security to him and withdraw their guards from the embassy.

"That was in absolute contradiction of orders given the major general by the ambassador," Tabatabai said, adding that he had confirmed the order in a telephone conversation with Zahedi from Morocco. "We are here to follow the ambassador's orders," he said.

The press attache could not say how many Iranian foreign service officers were at their posts in the embassy. The ousted faction said the embassy had been closed because all of the diplomats had left, and that Iranian consulates in New York, Chicago, San Francisco and Houston had closed in sympathy.

Meanwhile, about a dozen Iranians who quit the embassy three weeks ago rather than continue working with Zahedi, who is now the shah's closest political associate, signed a statement to be issued upon Khomeini's arrival in Iran.

The ayatollah was praised by them as "the great leader of the Islamic revolution" that would bring "justice, freedom and democracy" to Iran. The statement is to be issued in the name of the Coordinating Committee of Iranian Diplomats in North America.