An attempted coup against Thailand's military-backed government failed today after it collapsed from a violent beginning into a bizarre, almost comic-opera, sequence of events.

The five army officers charged with organizing the coup attempt were allowed to leave the country tonight, a government spokesman said. Led by retired deputy army commander, Gen. Chalard Hiranysiri - who had spent the last five months as a monk in a Bangkok Buddhist temple - the five flew to Taiwan, a favorite refuge for Thai political exiles.

[News agencies reported that the plotters were still at Bangkok's Don Muang airport several hours later for some unexplained reson.]

At 9 p.m. to 4:30 a.m. curfew was imposed on Bangkok.

Thailand premier Thanin Kraivichien appeared briefly on television and said the plotters had been allowed to leave to prevent further bloodshed. One senior officer and an enlisted man were killed in the attempted power grab.

The release of the plotters contrasted sharply with the harsh treatment of students at Bangkok's Thammasat University whose demonstration led to a military coup against the democratically elected government last Oct. 6. Nearly 50 students were shot to death by police and more than 2,000 were jailed, a number of whom are still being held.

Although Thanin assured viewers that the nation's stability was not affected, some political observers believed that the coup attempt could be just the start of more destablizing activities.

A number of ranking military officers, not just those who staged today's move but others still in command and even some in top government advisory positions, are known to oppose Thanin. For this reason, several observers said they believe that unless the premier is removed from office, or drastically changes his mode of operating, more coup attempts will follow.

In his TV appearance, Thanin referred to this dissent when he assured viewers that his government intended to "work toward democracy and improve the nation's economy." In the early hours of the day, when the coup-plotters controlled a radio station, they cited their dissatisfaction with these two areas of Thanin's administration as reasons for their takeover.

The premier, a former supreme court justice, was appointed to his office following last October's successful coup. A strident anti-Communist, he was expected to act as a front man for the army officers who held the real power.

Thanin, however, has shown headstrong single-mindedness in his drive to defeat Thailand's long-simmering Communist insurgency and to reform widespread official corruption. The premier has stepped on the toes of many ranking military officers who have traditionally profited from Thailand's flourishing narcotics traffic, prostitution and other illicit activities.

But these officers have failed to remove Thanin largely because of the support he enjoys from the nation's revered royal family. At the outset of his televised speech, the premier read a letter from Queen Sirikit to the widow of Lt. Gen. Arun Thawatasin, who was killed in the early hours of the aborted coup.

The death of Arun, the commander of the 1st Division, the unit that controls the Bangkok metropolitan area, evidently played a key role in causing the coup to fail. Division troops who might have gone along with the coup turned against it when they learned of their commander's death.

But a reason just as important for the coup's failure was astonishingly poor planning. Chalard and his cohorts had no more than 300 soldiers from the 9th Division, brought into the capital from their base in Kanchanaburi Province, on the Kwai River.

These troops, it later developed, knew nothing of why they were moved to Bangkok. Furthermore, their leaders' grasp of how to stage a coup was weak. After capturing the studios of a government radio station, the plotters failed to protect the station's transmitter.

Government forces simply cut the electricity and the coup-makers were off the air. The government, meanwhile, continued to broadcast all day over radio and television.

The plotters also briefly held the supreme government armored unit recaptured it, life in the fenced-in compound went on quite normally under the coup, with soldiers washing their cars in the backyard.

When two tanks dramatically smashed through the compound's main gate, a sentry was injured by a heavy gate post that crashed onto his head. There were no other casualties.

For some inexplicable reason, the rebels broadcast the misinformation that the coup was being led by deputy commander-in-chief of Thailand's army, Gen. Prasert Thammasiri. Prasert, it later developed, was being held hostage. When senior government officers appeared on television tonight, they announced that the general could not appear with team because he had fainted from hunder and thirst.

The plotters held onto their main operations post at the headquarters of the Internal Security Operations Command until after dark. But hours before Chalard and his top lieutenants inside negotiated their exile with Gen. Serm na Nakhorn, all but 10 of the 100 or so troops guarding the building surrendered peacefully.

A crowd of more than 1,000 which had gathered around the compound gate, applauded loudly each time a rebel soldier wandered out and turned over this M-16 riflet to government soldiers who sat on heavily armed tanks in the middle of tree-shaded Sukhothai Road.

During the entire 12-hour confrontation outside the compound, only two shots were fired, both by rebel soldiers and both by accident as weapons were being cleared. When the crowds dashed for cover the rebels laughed and shouted for them not to be afraid.

Asked why he was giving up without a struggle, one rebel soldier said, "Well, I've been talking to my friends inside and we realize that we didn't know why we'd been brought here until the people outside starting telling us about the coup. Then we decided that we didn't like the idea of Thais killing Thais. So, we quit."