President Francois Mitterrand, seeking to save his administration from a major political scandal, today accepted the resignation of his defense minister following allegations of government involvement and cover-up in the sinking of an antinuclear protest ship in New Zealand.

Political analysts said that the resignation of defense minister Charles Hernu, 62, represented a major blow to the Socialist government in the run up to crucial legislative elections next March. It was also seen as a great personal loss for Mitterrand, who has been a close friend of Hernu's for 30 years, and also marked one of the relatively few times in the history of the French Fifth Republic that a key minister has been forced out of office as a result of a series of damaging revelations in the press.

In a related development, the government fired the head of the secret service, Adm. Pierre Lacoste, for refusing to provide information about the role of French agents in the sabotage of a ship of the international environmental organization, Greenpeace, on July 10. A Portuguese-born photographer was killed in the explosion and two French agents are awaiting trial in New Zealand on charges of murder, arson and conspiracy.

Hernu's resignation followed a spate of press reports contradicting an official investigation that cleared both the government and the secret services of ordering the sinking of the Greenpeace ship, the Rainbow Warrior.

Several newspapers, including the respected Paris daily Le Monde, have published stories suggesting a cover-up.

Analysts said that, by sacrificing one of his closest political friends, Mitterrand appeared to be trying to avoid a drawn-out scandal that could fatally weaken his own authority as head of state. The "Greenpeace Affair" has already encouraged some right-wing politicians to step up demands for Mitterrand's own resignation in the likely event of an opposition victory in next year's elections for a new National Assembly.

Under normal circumstances, Mitterrand would expect to remain president until his seven-year term ends in May 1988.

The shake-up in the Defense Ministry was provoked by an angry letter last night from Mitterrand to Prime Minister Laurent Fabius complaining that he had been given insufficient information about the scandal. "This situation cannot continue," he added.

The official French investigation into the bombing, which drew on the testimony of Hernu and senior military officers, conceded that six French secret agents had been dispatched to New Zealand earlier this year. It insisted, however, that their mission was limited to gathering information about Greenpeace ships prior to their departure for the French nuclear testing center at Mururoa Atoll in the French Pacific.

In his reply to the president published today, Fabius said that Hernu asked Adm. Lacoste last night to respond in writing to press reports alleging that the Rainbow Warrior was sunk in an elaborate operation involving at least 10 French agents.

"Adm. Lacoste refused to reply to the defense minister, citing his understanding of his duties. It is obviously impossible to accept such a situation," wrote Fabius, urging that the secret service head be sacked.

In his resignation letter, Hernu said he had no choice but to leave the Defense Ministry after finding out, "in an incontrovertible manner," that his subordinates "had hidden the truth".

Replying to Hernu, Mitterrand expressed "pain" and "regret" at his resignation while praising his record as defense minister. Hernu, who has worked closely with Mitterrand for the past three decades, is widely known as one of the "most faithful of the faithful" of the president's aides.

As a senior adviser to Mitterrand, Hernu is widely credited with helping to reverse the Socialist Party's opposition in the 1960s and early 1970s to France's independent nuclear deterrent. Since taking over the Defense Ministry in May 1981 after the Socialist election victory, he won respect from Army officers and right-wing politicians for helping to forge a national consensus on defense policy.

The Elysee presidential palace named another Mitterrand loyalist, Paul Quiles, as Hernu's successor. Quiles, who was previously minister of urban development, housing and transportation, has also been given the task of finding out the truth about the Greenpeace Affair.

Reacting to today's shake-up, opposition spokesmen accused the government of looking for scapegoats to divert attention from the political responsibility of the president and the prime minister. They also demanded a parliamentary inquiry into the sinking of the Rainbow Warrior.

Press reports have named two other senior military officers who allegedly knew about the operation to sink the Rainbow Warrior. One is Gen. Jean Saulnier, the president's former top military aide, who has acknowledged authorizing special funds for a "reconnaissance" mission by French agents in New Zealand. The second is Gen. Jeannou Lacaze, former chief of staff of the French armed forces.

According to Fabius's letter to Mitterrand, both men were formally asked last night whether they knew of plans to blow up the Greenpeace ship. Unlike Adm. Lacoste, both replied that they had no knowledge of a sabotage mission.

Senior Socialist party leaders today accused Hernu of placing too much trust in the word of his senior military aides and hiding important details from Mitterrand. According to press reports, the president was not informed about the presence of French agents in New Zealand until a week after the Rainbow Warrior was sunk -- and then not by Hernu, but by Interior Minister Pierre Joxe.