NEW YORK (AP) _ Mayor Edward I. Koch said Thursday that he had fired his embattled chief medical examiner, Dr. Elliot M. Gross, nearly three years after allegations that his office may have altered autopsies to cover up police misconduct.

''The best interests of the office and this city require that I make a change at this time ... and provide new leadership to that office,'' Koch said in a letter to Gross, who has been the target of several state and local investigations.

The letter, made public Thursday, indicated the mayor met with Gross on Tuesday and sent the letter confirming the firing that day.

In a reply Thursday to Koch, Gross cited his 17 years as chief medical examiner, first for the state of Connecticut and then for New York City, and said he considered ''the reasons set forth for my removal to be without merit.'' His attorney said Gross would have further comment at a news conference Friday.

Earlier this month, a special mayoral advisory committee had recommended that Gross be replaced, saying that he was a good pathologist but lacked the managerial skills needed to run his office, which at 15,000 autopsies a year is the busiest coroner's office in the country. Gross steadfastly refused to step down.

It was the second mayoral panel appointed to study Gross' conduct since January 1985, when The New York Times published a series criticizing his office's handling of several cases of people dying while in police custody.

The Times, saying it had interviewed 250 sources, reported that Gross had altered autopsy reports done by other doctors, reached questionable conclusions in autopsies he conducted and delayed findings in the police cases. Gross strongly disputed the conclusions.

The first panel absolved Gross of misconduct but, like the second panel, criticized his management.

One of the most highly publicized cases was the death in 1983 of subway graffiti artist Michael Stewart following his 1983 arrest by transit police.

A pending state Health Department charge said Gross ''abrogated his responsibilities to determine the cause and manner of (Stewart's) death,'' neglected some findings from the autopsy and failed to determine that Stewart's death was the result of the confrontation with police.