The United States yesterday ordered Vietnam's chief U.N. delegate to leave the country because of alleged espionage activities, but Hanoi defiantly replied that its ambassador would stay put in New York.

The incident - marking the first attempt to expel a U.N. ambassador from the United States - threatened a clash with potentially serious consequences for the already agonizing movement toward normal U.S.-Vietnamese relations.

But, in its most immediate manifestations, it looked like a diplomats' version of an old-time slapstick movie, with Washington and Hanoi hurling the diplomatic equivalent of custard pies at each other against the back-drop of the United Nations.

On Tuesday, the ambassador, Dinh Ba Thi, was named an unindicted co-conspirator in a federal indictment charging Ronald Louis Humphrey an employe of the U.S. Information Agency, and David Truong a Vietnamese economist, with espionage on behalf of Hanoi.

Yesterday, the State Department announced that it had "request" Thi to leave. The department said the action was taken under a 1947 agreement, signed by all member countries of the United Nations, giving Washington the right to request the departure of U.N. diplomats "who have abused their privilege of residence."

Several hours later Vietnam struck back with a statement branding the U.S. charges as "a fabrication and slander" and saying that Thi would remain at his post. It concluded with an appeal to other U.N. members to "condemn this blatant, illegal action of the U.S. government and lend strong support to the correct stand of Vietnam in this question."

In Washington, U.S. officials acknowledged that Thi had refused to accept the diplomatic note requesting on the grounds that direct contacts between the two governments are conducted only in Paris. However, the officials said, the Vietnameses embassy in Paris had accepted a copy of the note.

The officials noted that the 1947 agreement has been invoked in the past to expel other diplomats from communist countries at the United Nations after they were caught in espionage activities. While the earlier cases involved individuals below the rank of ambassador, the officials said, the United States maintains that Vietnam is obligated to honor the request for Thi's ouster.

John Trattner, a State Department spokesman, said last night: "We haven't heard anything official from the Hanoi government that he won't leave. Our position is unchanged. We requested him to leave, and we assume he will leave as requested."

However, neither Trattner nor other U.S. officials would comment on what Washington might do if Thi does dig in his heels. Instead, they said only that State Department legal experts were studying the matter.

Despite the official refusal to comment, there seemed no possibility of the United States allowing a defiance of its request to go unchallenged. If efforts to resolve the matter through diplomatic means fail, Washington undoubtedly would feel compelled to have federal law enforcement officers seize Thi and put him on a plane out of the country.

When he announced the ouster order earlier yesterday, Trattner refused, for leagal reasons, to link it to the espionage case that surfaced Tuesday.

However, the indictment, returned in U.S. District court in Alexandria, named Thi as one of six Vietnamese officials with whom Humphrey and Truong conspired in their alleged espionage activities. The indictment did not specify the role allegedly played by the U.N. ambassador, who has displomatic immunity from prosecution, and U.S. officials have refused to comment on his links to the case.

The indictment alleges that Humphrey stole classified U.S. diplomatic cables from the USIA communications center and turned them over to Truong.

Truong, known as Truong Dinh Hung before he entered the United States in 1965, was charged in the indictment with turning the documents over to couriers at shopping centers and other locations for delivery to Vietnamese officials in Paris.

When he announced the move against Thi, Trattner carefully specified that it did not mean any change in the Carter administration's interest in continuing discussions with Hanoi about establishment of diplomatic relations. The last talks were held in Paris in December, and no new discussions have been scheduled.

However, Hanoi's statement yesterday took a more ominous tone about the possible effects of the incident on future discussions. It said, "They (U.S. officials) should cease these groundless fabrications if they really want to move toward improved relations: with the Socialist Republic of Vietnam."

Thi, 54, has been at the United Nations since 1974 following the communist takeover of South Vietnam. He became permanent observer of Vietnam in 1976 when North and South Vietnam were united; and, following Vietnam's admission as a U.N. member last September, he was named Hanoi's permanent representative.