A Navy captain, accused of having a homosexual affair with a sailor on his ship, will be court-martialed in Norfolk later this year, the Navy said yesterday.

Cmdr. Gerald M. Vanderwier, 42, a decorated Vietnam veteran, was relieved as skipper of the fast frigate USS Edward McDonnell in June while the Navy investigated charges that he had homosexual relations with a 21-year-old petty officer during a cruise last spring in the Mediterranean.

A court-martial on three counts of sodomy and two counts of conduct unbecoming to an officer was recommended last July after a two-day hearing in Mayport, Fla., where the McDonnell is based. Vice Adm. Edward S. Briggs, head of the Navy's Atlantic Surface Forces, yesterday ordered that Vanderwier be tried on the three sodomy charges, and dropped the other allegations.

Vanderwier, who is married, has denied the charges of homosexuality, according to Henry Coxe, his civilian attorney in Jacksonville. He declined further comment on the case.

A date for the court-martial won't be set until the judge, Capt. Maitland G. Freed, has had a chance to confer with the prosecutor and the defense attorneys, said Navy spokesman Lt. Cmdr. Robert Prucha. He said that the trial is unlikely to begin before next month.

The trial will be held in Norfolk because it has a larger number of officers who could serve as a jury of Vanderwier's peers, said Prucha. At least five officers will be selected to hear the court-martial proceedings.

Allegations of homosexual relations between Vanderwier and Petty Officer John Rainville, a hospital corpsman, first were reported last spring while the McDonnell was in the Mediterranean.

Rainville testified at the hearing in July that he had had sexual relations with Vanderwier three times -- twice aboard the ship. The officer's attorneys have challenged Rainville's credibility, saying that he has a history of mental instability and drug and alcohol abuse.