Foreign ministers of 35 Islamic countries sharply condemned the Soviet "military aggression" against Afghanistan today, calling it "a flagrant violation" of international law.

The delegates, in final voting here early this morning, also suspended Afghanistan from the world Islamic organization and urged all Ilsamic nations "to withhold recognition of the illegal regime in Afghanistan and sever diplomatic relations with that country until the complete withdrawal of Soviet troops."

The surprisingly strong condemnation of the Soviets, who have close ties to several of the Moslem countries, was the second major diplomatic setback for the Kremlin as a result of its invasion of Afghanistan a month ago and its installation of a pro-Soviet government. The United Nations General Assembly, by a 104 to 18 vote two weeks ago, demanded that the Soviets withdraw their troops.

The resolution approved here went much beyond a demand tha the Soviet troops be withdrawn and, unlike the U.N. resolution, mentioned the Soviet Union by name.

It said the conference "condemns the Soviet military aggression against the Afghan people, denounces and deplores it as a flagrant violation of international laws."

It demanded "the immediate and unconditional withdrawal of all Soviet troops stationed on Afghan territories" and said that "Soviet troops should refrain from acts of oppression and tyranny against the Afghan people and their struggling sons."

The resolution urged "all countries and peoples to secure the Soviet withdrawal through all possible means," wording that was seen as an invitation to continued diplomatic efforts to persuade the Soviets to remove their troops, as well as a plea for financial and other support for Afghan rebel forces fighting the Soviet invaders and the pro-Moscow government.

Six rebel groups who formed a united front Sunday appeared before the political committee of the Islamic conference yesterday to appeal for special recognition and "maximum military and economic assistance to continue their holy war," against the Afghan government. They asked that all Moslem countries "contribute liberally" to a special holy war fund.

Another element in the resolution called on Moslem countries to "envision" their "nonparticipation" in the Summer Olympics in Moscow, but four countries lodged reservations to this, substantially weakening the item.

In addition to the 35 Islamic countries, the Palestine Liberation Organization and a half dozen international Islamic groups took park in the emergency conference that began here Sunday.

There was no breakdown of the voting on the resolution condemning the Soviet Union, which took place behind closed doors, but the organization rarely makes such details public and professes to make its decisions by consensus.

"Every country present acceded to these items," conference chairman Agha Shahi told reporters after the vote.

Other resolutions still awaiting a vote early today dealt with the Egyptian-Israeli peace treaty, which is opposed by most Islamic countries, and Iran's efforts to censure the United States for exerting economic pressure to achieve the release of American hostages held in Tehran.

The passage of a resolution condemning the Soviet Union is a victory for Islamic states such as Pakistan and Saudi Arabia, which called for the strongest possible statement opposing Moscow's military takeover in Kabul a month ago.

This foreign minister's conference has been a balancing act between those Islamic nations that want to condemn the Soviet Union and those that want the United States to share blame with Moscow for interference in the region.

Saudi Arabian Foreign Minister Prince Saud, for instance, said on his arrival here Friday that the conference was not aimed at the Soviet Union, but rather at its actions in Afghanistan -- a subtle distinction meant to bring groups with close ties to Moscow such as Syria and the PLO.

Iran, for its part, pushed a resolution condemning foreign pressures on it, an obvious reference to U.S. efforts to impose economic sanctions to secure the release of the hostages seized in the U.S. Embassy in Tehran Nov. 4.

But according to a source close to the Iranian delegation, the conference political committee watered down the resolution so it does not mention the United States by name.

Separation of that resolution from the main measure condeming the Soviet Union was considered by diplomats to be a positive sign for the United States, which is trying to organize a cooperative security arrangement with Islamic nations to defend against further Soviet expansion into Pakistan and to the stratgic oil-producing nations of the Persian Gulf. i

The United States will face criticism in a resolution condemning the Camp David accords and the normalization of relations between Israel and Egypt, arranged via the Carter administration. Egypt was kicked out of the conference last year.

There was obviously intense backroom maneuvering among the diverse Islamic nations -- which stretch from Indonesia, with the most Moslems in the world, through the Arab Middle East, to Africa, which has a broad band of predominantly Moslem nations across its northern tier.

Although linked by a common religion, these nations have varied cultural backgrounds and political situations, which could have made it difficult to arrive at a consensus, explained one member of the Pakistani delegation.