-Anti-American demonstrations erupted here today as the Taiwan government reacted sharply and swiftly to the sudden U.S. announcement that the United States will recognize the Peking government and end its diplomatic ties with Taiwan.

Taiwan postponed its parliamentary elections scheduled for next week and the country's foreigh minister resigned.

Thousands of jeering demonstrators, dragging an American flag in the dirt, gathered outside the dingy yellow U.S. Embassy and U.S. military headquarters to denounce President Carter as a "coward" and to wave placards saying, "Down with Yankee bandits!"

Several threw rocks and eggs at embassy facilities.Marine guards used tear gas at one point to disperse demonstrators who had broken into the embassy compound. At an American military club here, a crowd of demonstrators broke windows, turned over two cars and damaged several other. Two Americans at the club were injured slightly when hit by objects thrown at them.

United Press International reported that one youth was arrested after breaking embassy windows with rocks. Police sources told UPI that a U.S. Army officer, who was not identified, was attacked on the street but escaped without injury.

The government of President Chiang Ching-kuo indefinitely suspended elections for seats on the Legislative Council and the National Assembly that had been scheduled for Dec. 23.

Independent candidates who had expected to do well against slates put up by a government dominated. by older officials from mainland China said they thought their chances had diminshed anyway, because of a popular urge to rally around the government.

Students who had supported the independents or had not been involved in politics were saying at the demonstrations that people ought to support the government in a crisis. One banner the Communists."

The government-controlled television reported that Shen Chang-huan, foreign minister since 1972, had resigned.

The action seemed to be largely a ritual assumption of blame, since Taiwan's foreign policy had little to do with President Carter's announcement early today local time of Washington's dipolmatic recognition of the Peking government and the planned U.S. troop withdrawal and closing of its embassy here. If anything, active lobbying by Taiwan diplomats in the United States helped persuade Carter to insit of the right to sell defensive arms to Taiwan and provide other security guarantees even after normalization with Peking.

Taiwan government reports of the American decision continue to ignore the American success at winning tacit Chinese approval for continued American arms sales to Taiwan.

Instead, Ting Shung-chiang, a leading theoretician for the ruling Kuo-mintang, or Nationalist Party, accused Carter in a television news interview of latching on to normalization with Peking as a way to obscure failures in the Middle East. Ting also repeated a theme that was popularized by some Nationalist candidates in the election that foreigners were disrupting the unity of the island's 17 million people.

The crowds outside the U.S. Embassy and at some other place in Taipei were restless but usually quiet except for some outbursts. One painting displayed in the crowd showed Carter groping blindly with an American flag covering his eyes.

"Yankee bandit" was shouted regularly by the demonstrators instead of the usual "Commie bandit," the favorite Taiwan term for Communists on the mainland.

One Chinese-speaking American who approached the crowd near the embassy heard some youths saying they planned to "pick up some pieces of Western meat," a threat directed at foreigners. As the passer-by walked away from the crowd, a man followed him asking in English, "Are you an American?" The American said no and escaped.

Inside the American Embassy today, several foreign service officers were meeting to assess the turn of events but declined to say anything about the activities.

An embassy spokesman said no one had been informed yet exactly when the embassy would be closed and what their news assignments would be. The spokesman said no unusual security procedures had been taken other than extra local police coming to handle the crowd. The spokesman said a similar large crowd had gathered outside the U.S. International Communication Agency office inKaohsiung, a large city at the south end of the island.

Although most people questioned here said they had been expecting an eventual American diplomatic pullout ever since President Nixon visited China in 1972, Most still said they were shocked at the loack of warning.

Some students at Taiwan University were shown on television weeping openly at news of the American decision.

A taxi driver said bitterly: "I fought with (American Gen. Joseph) Stilwell in the Burma theater. And now it comes to this."

Chi Cheng, former world champion sprinter, arrived at Taipei Airport tonight with her American husband, Vincent Reel, and their 3-year-old daughter for a Christmas visit.

"I think this will hurt the spirit of Taiwan but not the economy," she said.

The Nationalist Party's standing committee met today and reportedly decided to hold a conference Monday to consider what action to take in reaction to the American withdrawal.

President Chiang spoke to the nation over radio and television briefly, generally repeating his bitter dununciation of the American action issued this morning. He added a small note of conciliation, however, by thanking "all the Americans who have helped the Republic of China," as the Taiwan government calls itself.

Newspaper executives were called in by the Nationalist Party cultural affairs committee today and later passed on the party's guidance to local reporters. Journalists here said the party was interested in seeing some protest of the decision but not to the point where it might trigger violence.

A leading opposition candidate, Kang Ning-hsiang, called for an immediate suspension of all criticism of the Nationalist Party.

"They're weak now," he said. "Let's not make it tougher for them."

Public broadcasts urged people to remain calm and continually offered such popular slogans as "Don't be frightened by change," and "digntiy and self reliance."