President Carter condemned the Soviet Union in strong terms yesterday for the military intervention that toppled the government of Afghanistan, and dispatched a high U.S. official to consult urgently on the matter with European allies.

It was unclear what, if anything, the United States and its allies will do to counter the Soviet drive, which Carter described as "gross interference" in Afghan internal affairs "in blatant violation of accepted international rules of behavior."

An administration official who briefed White House reporters said it is nearly certain that "the traditional spirit of independence of the Afghan people" will bring about "sustained resistance" to Soviet domination. The official declined to say whether the United States or its allies might play some role in this resistance in the future.

The official declined to say whether the United States or its allies might play some role in this resistance in the future.

Much depends on "options which events themselves will create on the ground" as well as on the attitude of the nations in the area and the degree of outrage in the Moslem world about use of Soviet military force against the rebellion by Islamic Afghan tribesmen, the official said.

The suggestion was made that the Soviet military action against Afghan tribal resistance might have long-range repercussions on the 50 million Moslems in the Soviet Union, many of them residing in areas near the Afghan border.

Carter began consultations about the implications of the Soviet move -- and possible ways to counter it -- by cutting short his Camp David vacation and telephoning British Prime Minister Margaret Thatcher, German Chancellor Helmut Schmidt, French President Valery Giscard d'Estaing, Italian Prime Minister Francesco Cossiga and Gen. Mohammad Zia ul Haq, Pakistan's president.

All those he consulted, Carter said in a televised statement from the White House press room, agreed that the Soviet action in Afghanistan is "a grave threat to the peace."

Discussions with representatives of the European nations are to continue Sunday in London with Deputy Secretary of State Warren Christopher, who is flying there today for this purpose.

Carter also sent a personal message, believed to be a stiff protest, to Soviet President Leonid I. Brezhnev.

In his public statement, Carter compared the Soviet intervention in Afghanistan with the Soviets' use of armed force in Hungary in 1956 and in Czechoslovakia in 1968.

He went out of his way to note that this is the first time Soviet forces have gone into a Moslem country since the Russians occupied the Iranian province of Azerbaijan in the 1940's.

American officials have been gravely concerned about the reaction in the Middle East to the continuing U.S. conflict with Iran's Islamic revolutionary authorities. In the view of some officials, Soviet action against Islamic tribesmen in Afghanistan may deflect part of the anti-foreign passion in the Middle East to the Russians.

Officials are also closely watching the reaction in Iran, to see if the Soviet action next door in Afghanistan will suggest to Ayatollah Ruhollah Khomeini or members of his high council that Iran's conflict with the United States should be ended in Tehran's strategic interest.

President Harry S. Truman insisted that the Soviet forces evacuate Azerbaijan after World War ii, and the U.S. military umbrella had helped to ensure Iran's security against the Soviets from that time until the fall of the shah early this year.

After the sudden events in Afghanistan Thursday, Carter returned to the White House from Camp David at 9:45 a.m. yesterday and convened a two-hour meeting of the National Security Council, which discussed the Soviet action as well as the latest developments in the eight-week-long Iran crisis.

The White House announced that the president intends to remain here through the New Year holiday rather than returning to Camp David to complete his planned vacation.

According to administration officials, the expansion of the Soviet role in Afghanistan emerged from a two-month visit to that country by Gen. Ivan G. Pavlovsky, the overall commander of Soviet ground forces.

Pavlovsky and a survey team are said to have made a comprehensive study of the military requirements of the Afghan regime in combatting the widespread and growing insurgency in that country.

Afghan President Nur Mohammad Taraki was overthrown by his prime minister, Hafizullah Amin, in mid-September. This was evidently against the wishes of the Soviets, who are believed to have suggested that Taraki purge Amin rather than the other way around. Still, it was reported here yesterday that an abortive insurgency against Amin this fall had been crushed with the help of Soviet helicopter gunships.

According to American officials, Amin gave his acquiesence, if not enthusiastic approval, to the buildup of Soviet troops in Afghanistan in recent weeks, presumably to launch an offensive against the tribesmen and other Afghan rebels.

Amin played host in recent days to the Soviet ministers of health and minister of education, officials said. As late as 2:30 p.m. Thursday, just a few hours before he was deposed, Amin was reported to have received the visiting Soviet minister of communications, Nicolai Talazin, and the Soviet ambassador in an official "courtesy call."

U.S. officials said Soviet military forces were employed in the takeover actions at the presidential palace, defense ministry and radio station in Kabul. There was no indication of the role, if any, that Soviet forces played in the arrest and execution of Amin.

The U.S.-Soviet confrontation over Afghanistan comes at a time when Washington simultaneously is asking for Moscow's aid in placing international pressure on Iran through a U.N. economic embargo. Officials said there is yet no indication whether the Soviets will veto the U.S.-sponsored resolution of sanctions against Iran when it comes to a vote in the U.N. Security Council.

The U.S.-Soviet SALT II accord on strategic arms, pending in the Senate, is still formally supported by the Carter administration. But officials conceded that the Afghan events make SALT II's prospects in the Senate dimmer than ever.