The highest ranking defendant among the military officers who tried to overthrow the Spanish government a year ago testified today at the opening of the court-martial that he and others acted in the belief that they were carrying out the wishes of King Juan Carlos to curb the country's democracy.

The defense strategy of implicating the monarch in the dramatic seizure of Spain's Congress and Cabinet by rebel troops last Feb. 23 promises to heighten the tension surrounding the trial of the 32 officers, who include three generals.

The court-martial, which could bring sentences of up to 30 years on charges of military rebellion, is already viewed as a stern test of Spain's stability.

The heavy security cordon thrown around a suburban Madrid barracks where the proceedings opened contrasted with the apparent self-confidence of the accused, who are viewed as heroes by Spain's extreme right. Smartly turned out in uniforms and wearing their decorations, the defendants exchanged smiles and waved at their relatives as they sat down to face the 17 generals who form the court.

The opening day's testimony, however, produced directly contradictory statements from two key defendants, Gen. Jaime Milans del Bosch, 66, who was supreme commander of the eastern Valencia region at the time of the putsch, and Gen. Alfonso Armada, 61, who had been appointed deputy chief of the Army general staff two weeks earlier.

Milans, the highest ranking defendant, said in statements given to pretrial investigators and read to the court today that he had learned of the plan to seize the Congress through Armada and that he and others "had acted, convinced that his majesty was partly or wholly aware of the plans."

Milans cited a meeting he said he had with Armada six weeks before the coup attempt, shortly after Armada talked with the king during a skiing holiday. Milans claimed that Armada had confided to him the king's concern over government mismanagement, his fears over unrest in the Army and a wish that the democratic process be "redirected."

Col. Antonio Tejero Molina, who headed the group that seized the Congress building while the full Congress was in session, said in a statement to investigators that he would not have undertaken the action "if it had not been directed by Gen. Armada and under the king's orders."

But Armada, a wealthy aristocrat and a former tutor of Juan Carlos, flatly denied in his statement that he knew of the coup plans, said he had not mentioned the king during his meeting with Milans and denied a series of later contacts with the plotters alleged by the prosecution and in Milan's testimony.

The prosecution contends that Armada and Milans plotted the seizure of the Congress with Tejero, an extreme right-wing colonel of the Civil Guard whose entry into the chamber, waving his pistol, captured headlines around the world.

Milans backed up Tejero by declaring a state of siege in Valencia and, prosecutors charge, Armada intended to use the crisis to have himself named chief of government. Tejero held the Congress and Cabinet captive overnight, but the coup collapsed when Army leaders heeded the king's call to remain loyal.

The extreme right has never forgiven Juan Carlos for what they see as turning down the opportunity to restore the authoritarianism associated with the strongman rule of the late Francisco Franco. A strategy aimed at eroding the monarch's credibility was expected to form the main thrust of the rebels' defense.

The alleged involvement of Armada, whose family long has been identified with the monarchy, strengthens the conviction in rightist circles that Juan Carlos wanted the putsch but backed off at the last moment.

Both the government and the parliamentary opposition see the trial as an opportunity to redress the buffeting Spanish democracy received a year ago. Tough sentences against the defendants and their expulsion from the Army will, supporters of democracy hope, bring an end to the longstanding tradition of military meddling in politics and restore confidence in civilian stability.

There are fears, however, that the military court might be lenient to its fellow officers. Several of the defendants enjoy wide support among officers molded by Francoism.