UNITED NATIONS, SEPT. 22 -- Iranian President Ali Khamenei charged today that Monday's U.S. attack on an Iranian vessel has provoked a "very grave and immediate danger" in the Persian Gulf and warned that "the United States shall receive a proper response for this abominable act."

Secretary of State George P. Shultz scoffed at Khamenei's threats and announced that, in view of Tehran's attitude, the United States has begun U.N. Security Council consultations aimed at imposition of a worldwide arms embargo against Iran. Shultz added that the U.S. attack on the Iranian ship, which he said was laying mines in the gulf, was "well within our rights of self-defense." He declared that "we have repeatedly warned Iran that such activity cannot be tolerated, and we would act to protect our interests and those of international shipping in international waters."

In Britain, Prime Minister Margaret Thatcher strongly defended the U.S. action against the Iranian vessel {Details, Page A27}.

The sharply escalating tension and high-level verbal exchange between the United States and Iran came on the seventh anniversary of the start of the Iran-Iraq war, which has proven to be one of the longest and bloodiest military conflicts in modern history. Khamenei charged that the United States, which he referred to at times as the "Arch-Satan," was behind the Iraqi attack that started the war and many other ills that have challenged the Iranian regime.

The U.S. delegation in the U.N. General Assembly hall walked out as Khamenei denounced the U.S. version of Monday's incident as "a pack of lies" and threatened unspecified consequences. U.S. Ambassador Herbert S. Okun, who led the walkout, said, "I do not intend to sit by passively when our country is insulted, our president is pilloried and the truth is trampled."

The appearance here of Khamenei, the highest-ranking Iranian official to come here since 1980, was Tehran's chance to make its case to the international community against U.S.-led pressure for an arms embargo. Khamenei used the U.N. forum, and the world media spotlight that comes with it, in an other-worldly fashion more in keeping with his domestic role as a priestly prophet than his position as a political leader.

Except for a last-minute addition responding to Monday's military action, most of Khamenei's 80-minute address was read from a text that had been printed in advance as a hard-covered book, complete with gold-inked borders and intricate Islamic designs on each page, for distribution to surprised U.N. diplomats and press. Wearing priestly robes, a shawl and the black headdress of the Shiite Moslem clergy, the white-bearded protege of Ayatollah Ruhollah Khomeini made one of the most unusual presentations ever heard by the world body at a time of crisis.

As Khamenei entered the hall, Iranians in the audience shouted, "Allah Akbar!" ("God is great!") in a sharp departure from the usual decorum of the world body. Outside the building, more than 700 Iranian exiles demonstrated loudly, calling for Khomeini's overthrow.

The 47-year-old president and high priest began with prayers and used much of his address to portray "the miracle" of the Islamic revolution, the "seas of blood" that have flowed in its internal and external crises and the unyielding enmity of the United States.

The intense expectation that preceded Khamenei's appearance was heightened by President Reagan's challenge in the same hall 24 hours earlier that Khamenei should "clearly and unequivocally" state whether Iran will accept July's Security Council Resolution 598 demanding a cease-fire in the Iran-Iraq war and a return to international boundaries. Iraq has said it will accept the resolution if Iran does; Iran's failure to accept is the basis for the proposed arms embargo.

The answer was far less subtle and equivocal than most observers here had anticipated. Sources close to the Iranians said Monday's incidents, including the attack on a British freighter, may have been designed by Khamenei's domestic rivals to inhibit any concessions that he may have been prepared to offer.

Khamenei's declaration, as announced to an audience of almost rapt attention uncharacteristic of U.N. diplomats, did everything but explicitly reject the U.N. resolution. He attacked the Security Council as "a paper factory for issuing worthless and ineffective orders" and declared that it "has been pushed into this indecent, condemnable position by the will of some big powers, particularly the United States."

Khamenei described Iran's paramount and unyielding war aim as the condemnation and punishment of Iraq as "the aggressor," which the U.N. resolution does not do.

His only gesture to the United Nations was a statement added to his prepared text that Iran has conveyed its "unequivocal viewpoint" to the world body through Secretary General Javier Perez de Cuellar and "expects" the Security Council "to use correctly the possibilities open to it." A U.N. aide saw that as a reference to a de facto cease-fire, initially unacknowledged by Iran, that Tehran authorities are reported to have offered Perez de Cuellar on his trip there in mid-September.

Iraq and the United States have publicly rejected this idea, and Washington has made no secret of its view that the time has come to penalize Iran for refusing to end the war by adopting the mandatory arms embargo.

British Foreign Secretary Geoffrey Howe said after the address that the combination of the Iranian military action Monday and Khamenei's speech would strongly impel "the imposition of an embargo" against Iran.

Shultz seemed to agree, saying that Khamenei's speech "did not constitute by any means an acceptance" of the U.N. resolution and announcing that "we're proceeding" with consultations looking toward an arms embargo.

A senior U.S. official said Undersecretary of State Michael H. Armacost and Assistant Secretary of State Richard W. Murphy had begun informal efforts to obtain Security Council approval of the arms embargo and that formal consultations will begin Wednesday in a meeting of ambassadors of the five permanent members of the Security Council -- the Soviet Union, China, the United States, Britain and France.

Following a meeting with Khamenei tonight, the current president of the Security Council, Ambassador James V. Gbeho of Ghana, said he was encouraged and that he believes "this is a time for quiet diplomacy" to head off a clash with Iran over the arms embargo. However, he indicated that the main elements of the Iranian position remain unchanged.

The events in the gulf and Khamenei's sharp attack seemed likely to upset new U.S. efforts to open a direct dialogue with Iran.

Before the incident, Washington had sent messages to Tehran through the Swiss and Algerians asking whether the Iranians were interested in a meeting during Khamenei's visit, according to diplomatic sources.

The sources said the Iranians had not given a clear reply, but they said there had been "back and forth discussion" about a possible meeting. The two countries severed diplomatic relations in 1979.

A notable feature of Khamenei's address, remarked on by various U.N. delegates, was the absence of any criticism of the Soviet Union except for a passing reference to Afghanistan and almost total concentration on attacks on the United States. A Third World foreign minister said this appeared to be part of Tehran's bid for Soviet support in the coming U.N. political struggle.

Khamenei said Monday's U.S. attack was against "a merchant ship, not a military speedboat," and that "this is the beginning of a series of events the bitter consequences of which shall not be restricted to the Persian Gulf."

He said, without any specifics, that "the United States, as the initiator of the trouble, shall bear responsibility for all ensuing events."

At one point Khamenei said Iran's quarrel is with "the leaders of the U.S. regime" and not with the American people. In an effort to reach the U.S. and international public, Khamenei is to hold a breakfast meeting with U.S. editors at the Waldorf-Astoria Hotel Wednesday, followed by a full-scale news conference in the Waldorf's Starlight Roof and taping of an hour-long edition of ABC's "Nightline" before returning to Tehran late in the day.

Staff writer David B. Ottaway, in Washington, and special correspondent Michael J. Berlin contributed to this report.