A detachment of Spain's paramilitary Civil Guards stormed into the Spanish parliament and took the Cabinet and assembly hostage yesterday in an attempted coup d'etat against the nation's still fragile post-Franco democracy.

Amid uncertainty over the intentions of the country's 20,000-member armed forces, King Juan Carlos went on national television early this morning wearing the uniform of a captain general in the Spanish armed forces and declared that the military is backing him against the rebel Civil Guardsmen, who were holding more than 300 legislators at gunpoint.

The attempted coup marked Spain's most serious crisis since the death in 1975 of Generalissimo Francisco Franco. It was touched off by a disgraced Civil Guard colonel who broke into the parliament chamber early yesterday evening, firing shots from his pistol, at the start of a vote to confirm a new prime minister. The colonel, Antonio Tejero Molina, leveled his pistol at the house speaker presiding over the vote and ordered all the deputies to lie on the ground face down and await further instructions. The paunchy colonel, waiving the pistol in his right hand and gesticulating with his left, was backed by about 200 Civil Guardsmen brandishing submachine guns.

At the same time, a state of emergency was declared by the chief military officer of the eastern Valencia region in seeming coordination with the Civil Guard rebels inside parliament, with whom he reportedly was in telephone contact.

Immediately following the king's speech, however, he ordered his troops back to their barracks in an apparent decision to remain loyal to the monarch.

Tejero told a Spanish journalist who managed to reach him by telephone inside the building that the negotiator the king had sent to deal with him had offered him a plane to leave the country but that he had refused. The colonel said that he was demanding the dissolution of parliament, the establishment of a military junta to rule the country and a campaign to "eradicate terrorism."

Looking tense, the king said in a three-minute address delivered three hours later than originally scheduled, "The crown cannot tolerate any action against the constitutional order of the Spanish people."

He said he had ordered authorities throughout the country to maintain or restore order.

The standoff at the parliament building continued into the early hours this morning. Civil Guards holding the deputies inside appeared increasingly isolated. As each hour passed, more contingents of other police moved in to reinforce the outer ring of units opposing the rebels. Those forces included a number of other Civil Guardsmen obeying the king's orders.

From time to time rebel guardsmen came to the grillwork fence of the parliament compound and yelled such things to their former comrades outside as "Long live Spain," and "You're gutless."

There were indications at about 4 a.m. Madrid time that the rebels might be preparing to give in. Some soldiers were seen moving from the outer ring of forces into the courtyard of the parliament building.

Madrid newspapers hit the streets with extras backing the king and the constitution. The newspaper Diario 16 headlined its story, "The Coup d'Etat Is Broken."

The main worry as the morning wore on seemed to be how to get the 350 members of the lower house out safely. A major complication seemed to be that a number of top political leaders such as outgoing moderate premier Adolfo Suarez -- who resigned last month in a political quarrel linked to the government's inability to rein in terrorists -- Socialist leader Santiago Carrillo and others were being held in separate rooms so that any more against the main parliamentary chamber might endanger those leaders.

Shortly before his speech was broadcast, the king had sent his most trusted and loyal general, Alfonso Armada, from the royal palace to the parliament to negotiate. The talks continued early this morning.

The highly respected general was for many years the king's personal aide de camp and is now deputy chief of staff.

Socialist and communist labor unions in the Madrid area appealed to workers for calm, saying that this was "an isolated incident that was apparently not supported by the armed forces."

Tejero, the would-be coup leader, was indicted for sedition after an earlier coup plot in 1978 that never moved into the operational stage. Last spring, a court-martial sentenced him to seven months in prison for his part in what was known as the Galaxy plot.

He was released immediately upon sentencing, since he had spent that long awaiting trial. That leniency was seen as reflecting military reluctance to punish him severely.

But the commanders of the Civil Guard and Spain's other national police force both denied last night that their organizations had any official part in the coup attempt in parliament. A ring of national and Madrid city police surrounded the gray-uniformed Civil Guard unit of about 200 who were holding the parliament building.

The Civil Guard, a paramilitary national police force with a distinctive three-cornered black hat and a reputation as a bastion of rightist sentiment, faced the other police forces with automatic weapons at the ready. But there were no reports of fighting.

The Army chiefs, in an apparent indication of loyalty to the king, issued a communique calling the coup attempt an "attack on the constitution" and pledging that "all necessary methods have been taken" to restore order.

The Interior Ministry said civil governors controlled their regions across the country.

Army troops quickly occupied the state radio and television networks, apparently to guard them against rebel Civil Guardsmen, news agencies reported. The state radio network played light music interspersed by martial airs. One independent radio station reported that Juan Carlos, a key to the evolution of the coup attempt, ordered all ministerial under secretaries and senior members of his administration not captive inside the parliament, or Cortes, to sit in a nonstop meeting as long as the crisis goes on.

A similar meeting was understood to be taking place among the Army chiefs.

It appeared that crucial negotiations were taking place between the palace, the military and representatives of the government and administration while parliament and the Cabinet were held hostage. One big unknown was how lower officers from the regular Army, as distinct from the Civil Guard, would view the coup attempt. The chiefs of staff evidently were trying in their declaration to make it clear that they opposed the move.

The Valencia regional commander, Gen. Jaime Milans del Bosch, had announced a dusk-to-dawn curfew and prohibited groups of more than four from gathering in the streets. Milans de Bosch, who in his communique denounced a "vacuum of power" in Madrid, is known throughout Spain for his right-wing views and as a frequent critic of democracy.

Suarez's designated successor, Leopoldo Calvo-Sotelo, apparently remained inside the main parliamentary chamber. It was during a preliminary debate on Calvo-Sotelo's nomination that the Civil Guard troops burst in.

Removed from the chamber in addition to Suarez, Gonzalez, Santiago Carrillo were the defense minister, the deputy prime minister with responsibility for military affairs and the Socialist Party parliamentary spokesman, a report by an independant radio station said.

The report said Tejero read out the state of emergency communique issued in Valencia to the assembled members of the government and parliament. Along with the reported telephone conversations, this was taken as an indication that the Madrid and Valencia actions were corrdinated.

Jounalists attending the debate who witnessed the attack the debate who witnessed the attack were allowed to leave after the Civil Guard confiscated their cameras, films and notebooks. They said nobody appeared to be injured in the sudden takeover and that as they left, the legislators were sitting in their seats, forbidden to speak and awaiting developments.

Their debate was being transmitted live on radio when the Civil Guard troops stormed in. Shots were heard and a voice ordered all to lie down.

The attempted coup came just as the power vacuum that set in after Suarez's resignation had a chance of resolution in the succession of Calvo-Sotelo. The prime minister-designate had narrowly failed to gain overall parliamentary endorsement for his nomination last week and was due to win today on a simple majority vote.

But in addition to the feeling of government indecisiveness toward the terrorists, the coup attempt reflects a deep military resentment over the rapid changeover from dictatorship to democracy. Juan Carlos has been the prime mover behind the transition and Suarez, who was originally picked by the monarch to head his government, was the chief architect of what has often been called "the Spanish miracle."

Suarez lifted the Francoist bans on political parties and trade unions and steered Spain through adoption of a democratic constitution that instituted free elections and representative government. Military opposition to democracy focused on legalization of the Communist Party and on the government policy of creating regional autonomy with a wide measure of self-rule.

Anticommunism was the main ideological plank of Francoism and the glory of Spain was its most sacred tenet. Over the past year autonomy has been granted to the Basque country and to the northeastern region of Catalonia, restoring the self-government that both areas enjoyed before Franco's rebellion against the republic of the 1930s triggered the Spanish Civil War.

Fueling Army unrest was the continuing terrorism of the ETA Basque separatist organization. The struggle claimed nearly 100 lives last year. In its latest action, ETA kidnaped three honorary consuls in the Basque region Thursday night and is holding them until the national media publish reports of the police torture of ETA suspects.

The death of an ETA suspect earlier this month while in police custody caused widespread pro-ETA demonstrations and undid much of the good will created by Juan Carlos during a recent official visit to the Basque country.

In addition, the arrest of five police inspectors, the Madrid medical officer and an information official in connection with the suspect's death led to the protest resignations of at least seven senior police officials. Leftist opposition politicians called for a purge of police forces, breaking a tacit agreement to steer away from such sensitive subjects in the interests of solidifying Spanish democracy.

Juan Carlos, who is constitutionally commander-in-chief of the armed forces, is the key element in the unfolding test of Spain's experiment with democracy. He recently confided to foreign journalists that he did not believe the Army as an institution would stage a coup against the country's democracy.

Juan Carlos is intimately identified with the democratic process. A socialist legislator recently said that should the Army take over Spain he himself would leave the country on the next plane and that he fully expected to find Juan Carlos sitting in the adjacent seat.

Observers found it surprising that a plot should have matured into a takeover of parliament, causing the confusion that descended on Madrid and the rest of Spain during the night.

Outside the parliament building four groups of right-wingers gathered shouting "Long live the Army. Army to power." The crowd of onlookers was kept a good distance from the building, which was surrounded by members of the Civil Guard armed with automatic weapons.

The streets of Madrid emptied quickly as people remained home listening to the radio. The overall impression was one of disbelief that such a coup could have been attempted.

Except for police vans around the area of the parliament, the rest of the capital was eerily quiet, Washington Post correspondent Ronald Koven reported. No police or military could be seen anywhere in the rest of the city or during the long drive from the airport.

There was relatively little traffic and few pedestrians. at the airport, which is normally under Civil Guard jurisdiction, there were far fewer than the usual number of paramilitary formalities imposed for entering the country.