The fate of a triple murderer known as "Japan's Gary Gilmore" because he wants to be executed has raised thorny medical and legal issues for justice officials here.

Only the minister of justice can now frustrate carpenter Matsuzo Ohama's desire to be hanged, although a court psychiatrist, his lawyer and a protest group insist he is insane.

The case originally attracted publicity because of superficial similarities with the bizarre saga of convicted killer Gary Gilmore, who sought execution and was finally shot Jan. 17 at the Utah state prison.

"Both men wanted to die. The difference is that Gilmore was sane and this man is not," said Ohama's court-appointed attorney, Yoshimitsu Imoto, 69.

So far the killer's deathwish has short-circulited the Japanese court system, puzzled his supporters and defied his lawyer's efforts to save him. Last month the deadline for filing a Supreme Court appeal ran out.

"I told him, 'This is the last chance - please call me anytime,'" said Imoto. "I waited by the telephone up to midnight but he didn't call. At our last meeting he said, 'My life is over. I want to die'."

Now the case is under final review at the Justice Ministry. If and when the court sentence is upheld, Ohama will go to the gallows within five days.

The controversy is not over the principle of capital punishment. Japan has an extraordinarily low murder rate - approximately 2,000 a year in a population of 111 million - and the execution of 10 or so of the worst criminals annually does not provoke major opposition.

There is serious doubt, however, about Ohama's mental fitness to seek his own conviction and death. People close to the case believe it poses serious questions about Japanese attitudes toward criminal insanity.

After 38 years as a prosecutor and defender, the silver-haired Imoto has lost more sleep over this case than any other: "If the judges are mistaken," he said gravely, "it is an irretrievable tragedy for Ohama, for me and for Japanese justice."

In August 1974, Ohama killed a woman neighbor and her two young daughters because the sound of their piano practice became intolerable to him. He was a notable eccentric, carrying a fishing rod everywhere, and was under psychiatric care for an obsessive sensitivity to noise.

According to his lawyer, Ohama believed that the neighbors were trying to kill him with their scale-playing, and acted in self-defense.

The emphasis on harmony and co-operation in Japanese culture is echoed in the justice system and Ohama's judges were empowered to show a wide latitude of mercy in sentencing a truly penitent killer. Ohama still feels no remorse and has written thousands of pages to rationalize his crime. The court found him neurotic but competent to stand trial, and sentenced him to death.

The verdict was bitterly criticized by an association of noise pollution victims. "The man is himself a victim," said one official, "the brutal noise drove him insane. I know how he felt, I sometimes feel I myself could kill."

The case gained notoriety as "piano satsujin," piano murder. Noise pollution is a bane of Japanese city life, and the piano as a popular symbol of affluence has become a common source of quarrels among neighbors. Pro and anti-piano factions wrote and called the newspapers to give their opinion. Ohama, headlined as "piano-hating man," was meanwhile being tortured by noise in jail and gradually relinquished his desire to live, according to Imoto.

The murderer's wife divorced him and his family abandoned him. Soon the conscientious old lawyer earning only meager public defender fees was his only visitor.

"I feel very sorry for him," said Imoto. "Ordinary people cannot understand how he suffers. He told me, 'No need to go on with the trial. I want to die.'"

The lawyer felt it has duty to appeal, against Ohama's wishes. He had elicited psychiatric testimony that Ohama was paranoid and not responsible for his actions when the defendant abruptly withdrew the appeal.

Although the psychiatric evidence indicated that Ohama was at least partially insane, another court rejected lawyer Imoto's appeal and ruled his client fit to make legal decisions governing his survival.

The unfortunate Ohama, whose noise phobia was so severe he could listen to the television only with an earphone, lives in the clamor of the jailhouse and looks forward only to his death.

Imoto, a gray-suited figure with a starched white collar, is suddenly perplexed after a lifetime of loyalty to the law. "All the court procedures were legal," he says, but he feels that the outcome was wrong.

If the justice minister puts his seal on the execution order, public concern may thwart Ohama's hunger for execution. He is one of 19 Japanese criminals under death sentence, and some of his Death Row colleagues have been there for years. The conciliatory nature of Japanese society can even stay the hangman's noose. Public indignation or continued pleas of innocence by a prisoner may postpone an execution indefinitely.

In the most famous case, Hirasawa Sadamichi was convicted of poisoning 12 people to death in a Tokyo bank in 1948. Lingering doubts over his guilt have delayed his execution 22 years. Now 35, he is expected to die a natural death.