With champagne glasses held high, federal and California officials toasted victory over the Mediterranean fruit fly yesterday, ending a two-year, $96 million battle to eradicate the voracious pest that threatened the state's multibillion-dollar agriculture industry.

On hand for the victory party was C. W. (Bill) McMillan, assistant secretary of Agriculture for marketing and inspection services, whose department had once accused the Golden State of not taking tough enough steps to fight the insect. But that harsh exchange was forgotten yesterday.

At the height of the battle, the state quarantined 623.5 square miles and employed 4,000 workers as the blue-eyed bugs turned up in backyards from Los Angeles to the northern reaches of the lush San Joaquin Valley.

The state released 4.5 billion sterile Medflies, hoping the fertile pests would choose one as a life-long mate, and sprayed the pesticide malathion on 1,495 square miles after the first fly was found in a San Jose garden on June 5, 1980. One person died when a helicopter that was spraying pesticides crashed.

The last fly was found this past July 21 in Los Angeles, where the flies have tried to establish a colony for decades. Officials expect them to try again, but this time they say they will be ready.

Agriculture is California's leading industry, with gross annual revenues of $14 billion. Medflies infest 256 varieties of fruits and vegetables, including 19 crops worth $5.4 billion to the state.

The failure to initiate aerial spraying in the early part of the campaign stirred a controversy that prompted federal officials to threaten California with an embargo. Tensions eased as the state gained control over the infestation.

Nearly $2 billion in lawsuits and damage claims are pending against the state because of the eradication effort.