A marine who threw tear gas canisters into a gay bar on Capitol Hill last June was sentenced to nine months in prison yesterday, and an accomplice was put on probation and ordered to provide $3,000 in restitution to the bar's owners.

"A very cruel and malicious act was done against people and I have no doubt it was done because they were gay," said D.C. Superior Court Judge Frank E. Schwelb, who added that the punishment should serve as a deterrent against any such future aggression by marines stationed here. Schwelb compared the incident, which occurred at the Equus bar, 639 Pennsylvania Ave. SE, to the persecution of blacks by the Ku Klux Klan, and of Jews by Nazis.

Schwelb sentenced Pfc. William J. Davidson, 23, who had a previous criminal record, to nine months, and Pfc. David H. Jenkins, 19, to one year's probation on the condition he pay $3,000 restitution to the Equus' owners. Both men are stationed at the Marine Barracks at Eighth and I streets SE, home of the commandant of the Marine Corps and a 1,000-man garrison.

Davidson and Jenkins pleaded guilty last July to one count of destruction of property. Each could have been sentenced to one year in prison and a $1,000 fine.

According to court records, Davidson and Jenkins entered the Equus after midnight on June 13 and tossed two tear gas canisters into the crowd of some 40 patrons. The frightened and disoriented customers scrambled out the front door, coughing and vomiting. One man was taken to a local hospital where he was treated and released.

Davidson told Schwelb that the Equus raid was staged "more or less for the people around us. It would be something that would be laughed at by an average marine. It wasn't meant to harm anybody."

"It was an act of stupidity," Jenkins said.

Lawyers for the two marines said the act had been a prank; one compared it to a college "panty raid." "There's a certain macho element in this," one of the lawyers said.

"That's macho?" the judge replied. "That's manly? To throw that in the bar of a vilified minority? . . . What do you think it was calculated to inflict -- joy?"

The bar was closed for several days while repairs were made, resulting in a loss of about $2,500, according to prosecutor Mary Ellen Abrecht. Club owners Ric Holloway and Denny Graham both expressed satisfaction with the sentences.

The Equus incident was the latest in a series of clashes between marines and members of the homosexual community, which have been centered at the Equus and other gay bars, and at the Iwo Jima Memorial, which has been a meeting place for homosexuals. The post commander at Eighth and I streets, Col. O.K. Steele, recently instituted Marine patrols around Capitol Hill gay bars in an attempt to prevent further incidents. .