Spain's supreme military court today sentenced the two ringleaders of last year's rightist military coup attempt to maximum 30-year sentences, but showed leniency to 31 other defendants indicted on charges of military rebellion.

The judges acquitted 11 officers and gave minimum sentences of two to three years to nine others involved in the abortive coup, in which the Spanish parliament was held at gunpoint for 18 hours. The nine, after completing their sentences, would be permitted to return to active Army service.

Prime Minister Leopoldo Calvo-Sotelo, one of those held hostage during the siege, said in a radio interview, "I am worried about the sentences," and said his government planned to appeal them.

Echoing the premier's words, Inigo Cavero, secretary general of the governing Union of the Democratic Center party and also a hostage victim, said, "As an eyewitness of what happened, several sentences are excessively benign."

The decision to appeal underlined the undisguised anger felt in many Spanish political circles over the sentences. The leniency shown at the end of the tense three-month-long court-martial was viewed as virtual vindication of the coup attempt. The influential news magazine Cambio 16 tonight was preparing a cover story on the sentences headlined "A National Disgrace."

An aide to the prime minister said the government would ask a civilian court to overrule the military tribunal. Such a ruling would have no precedent in Spanish law, which has traditionally respected the privilege of the military to judge itself.

The court-martial gave maximum sentences to Gen. Jaime Milans del Bosch, who declared a state of siege in the eastern Valencia region on the day of the coup, and Col. Antonio Tejero of the Civil Guard, who spearheaded the Feb. 23 putsch by seizing the Congress building at pistol point. Both Milans, one of the most decorated officers in the Spanish Army, and the flamboyant Tejero are considered folk heroes among the extreme Spanish right.

Eight Civil Guard lieutenants who on Tejero's orders commanded about 300 guardsmen in the Congress seizure were set free. The prosecutor had demanded sentences of longer than three years against them, which would have meant automatic expulsion from the guard.

Among those treated leniently were four Army captains of an elite armored division stationed outside Madrid who joined Tejero and his men after the seizure began. The prosecutor had demanded sentences of five to six years against the captains but the court-martial ordered terms of two to three years.

Their superior officer, Maj. Ricardo Pardo Zancada, for whom the prosecution demanded a 15-year term, was sentenced to six years.

The judges also treated lightly two other generals, Alfonso Armada, who the prosecution claimed was the rebel choice to head a military-backed government, and Luis Torres, a one-time commander of the Madrid Armored Division, accused of attempting to rally his former division during the coup attempt. The prosecutor had demanded terms of 30 and 15 years respectively against Armada and Torres, but both were sentenced to six years.