The Supreme Court, restoring to the armed forces sweeping authority to prosecute service personnel, ruled 5 to 4 yesterday that military personnel can be court-martialed even if their crimes occurred off base and were not connected to their service.

The decision, which affects 2.1 million armed forces personnel, overturned a controversial 1969 ruling by the court that had come under attack by the Reagan administration and Defense Department officials as constitutionally flawed and impossible to administer.

Under the 1969 ruling, soldiers accused of off-base offenses have often been tried in civilian courts where they have constitutional protections not afforded by the military system, including indictment only by a grand jury and a trial by a jury of one's peers.

But Chief Justice William H. Rehnquist, writing for the court in Solorio v. U.S., said the court under then-Chief Justice Earl Warren was wrong in ruling that the framers of the Constitution only intended to give the military the authority to prosecute crimes that were "service-related."

In another victory for the military yesterday, the court ruled, again 5 to 4, that a former Army sergeant could not sue for injuries he suffered as a result of his unknowing participation in a secret Army drug experimentation program involving the hallucinogen LSD.

Justice Antonin Scalia, writing for the court, said such suits could not be permitted because they would "require judicial . . . intrusion upon military matters . . . {and} would disrupt the military regime."

The ruling in U.S. v. Stanley prompted a harsh dissent by Justice William J. Brennan Jr., who likened the Army's drug experiments on some 1,000 soldiers to human experimentation programs carried on by the Nazis.

The court-martial case is likely to have the greatest impact in the area of prosecuting off-base drug offenses. Several thousand cases involving military personnel that have been tried each year in civilian courts can now be tried by military courts.

The ruling involved Richard Solorio, a Coast Guardsman who was accused of sexually assaulting the young daughters of fellow servicemen in New York and Alaska. The New York crimes occurred on base, but there was no base in Alaska and the crimes alleged there occurred in his house.

At his court-martial, Solorio argued there was no "service connection" involved in the Alaska crimes and asked to have those charges dismissed. The court-martial judge agreed but two military appeals courts reinstated the charges.

The 1969 case, O'Callahan v. Parker, involved James F. O'Callahan, an Army sergeant stationed in Hawaii who was in civilian clothes on an evening pass when he broke into a hotel room and attempted to rape a woman. Honolulu city police, after learning that he was in the armed forces, turned him over to the military police and he was court-martialed and sentenced to 10 years' hard labor.

Rehnquist, upholding the military appeals courts, said the court's ruling, which occurred at the height of resistance to the Vietnam war, improperly interpreted the Constitution's grant of power to Congress alone to make rules for the military.

"In an unbroken line of decisions from 1866 to 1960," Rehnquist said, "this court interpreted the Constitution" to condition military jurisdiction "on one factor: the military status of the accused."

The new test, that only military courts could prosecute crimes that were "service-connected," was not justified by historical analysis of the intentions of the founding fathers, Rehnquist said, and the "plain language" of the Constitution would require the Supreme Court to refrain from regulating the military justice system.

"We therefore hold," Rehnquist said, "that the requirements of the Constitution are not violated where, as here, a court-martial is convened to try a serviceman who was a member of the armed services at the time of the offense charged." Justice Byron R. White, who dissented from the 1969 decision, and Justices Lewis F. Powell Jr., Sandra Day O'Connor and Scalia, joined Rehnquist.

Justice Thurgood Marshall, in dissent, said the 1969 decision was not based on whether Congress could regulate military trials, but on whether Fifth Amendment protections at criminal trials applied to the military.

"Unless Congress acts to avoid the consequences of this case," Marshall said, "every member of our armed forces . . . can now be subjected to court-martial jurisdiction -- without grand jury indictment or trial by jury -- for any offense, from tax fraud to passing a bad check, regardless of its lack of relation to military discipline, morale and fitness."

Justice John Paul Stevens, while agreeing with the majority that Solorio could be court-martialed for the Alaska crimes, strongly criticized the majority for overruling the 1969 case. The majority "has no business reaching out" to take the "drastic action" of overruling the 1969 case, he said.

"The fact that any five members of the court have the power to reconsider settled precedents at random, does not make the practice legitimate," Stevens said.

The LSD case began in 1958, when Sgt. James B. Stanley volunteered to participate in a program he was told was designed to test military equipment and protective clothing for chemical warfare. But, unknown to him, Army officials and others at the Aberdeen Proving Grounds in Maryland gave him LSD on four occasions. The Army discharged him in 1969.

Stanley became aware of the experiments in 1975, when the Army sent him a letter asking him to participate in a follow-up study. Stanley sued but his case was dismissed under a 1950 ruling that bars servicemen from suing their superiors for service-related injuries. An appeals court, however, reinstated his claims.

Brennan, joined by Marshall and Stevens in dissent, said the "practical result of this decision is absolute immunity from liability for money damages for all federal officials who intentionally violate the constitutional rights of those serving in the military."

Justice O'Connor, also in dissent, said that, "in my view, conduct of the type alleged in this case is so far beyond the bounds of human decency that as a matter of law it simply cannot be considered a part of the military mission." O'Connor said "no judicially crafted rule should insulate from liability the involuntary and unknowing human experimentation alleged to have occurred in this case."