General Dynamics Corp. and four present or former executives, including NASA Administrator James M. Beggs, were indicted yesterday on charges of trying to defraud the government on the development of an ill-fated Army weapon.

The defendants were charged with attempting to hide cost overruns on a contract to develop the Divad antiaircraft gun by illegally shifting excess costs to two other General Dynamics accounts also funded by the Defense Department. Justice Department officials said the overcharges amounted to $7.5 million on the $40 million Army contract, which was to build two prototypes of the gun.

Beggs, 59, head of the National Aeronautics and Space Administration since June 1981, was an executive vice president and director of General Dynamics when the company was competing unsuccessfully for a much larger contract, worth $5 billion, to produce the Division Air Defense (Divad) gun. The controversial weapon, also known as the Sgt. York, was canceled in August by Defense Secretary Caspar W. Weinberger.

The indictment by a federal grand jury in Los Angeles charges that Beggs, three other executives and the nation's third-largest defense contractor conspired to defraud the Pentagon on the Divad contract from January 1978 to August 1981. The seven-count indictment also charges them with making false statements in the matter.

Beggs, who lives in Bethesda, said in a statement, "I am innocent of any criminal wrongdoing, and I intend to vigorously defend the case. I am confident that after all the evidence is aired, I will be exonerated."

General Dynamics said in a statement that the company and its employes would fight the charges. The St. Louis-based contractor said the indictments involved "cost-accounting judgments which were made more than five years ago" and that the issue was "a highly sophisticated regulatory and accounting matter which should be resolved in a civil forum, not in a criminal case . . . . We are confident that when our side is heard, we will prevail."

The company, which received $6 billion in defense contracts last year, could face an immediate suspension because of the indictment and, under Pentagon rules, could be debarred from military work if convicted on the felony charges. Pentagon spokesmen said only that the indictment is under study.

The indictment is the latest setback for General Dynamics, which remains the subject of several federal investigations on charges ranging from deliberately underbidding on submarine contracts to improperly charging the Navy for travel and entertainment expenses. In May, the Navy suspended $1 billion worth of General Dynamics contracts because of the improper claims and fined the company $676,283 for giving illegal gratuities to retired Navy Adm. Hyman G. Rickover. The suspension was lifted 12 weeks later.

The indictment, produced by the Justice Department's Defense Procurement Fraud Unit, named three current General Dynamics employes. They are Ralph E. Hawes Jr., a vice president who formerly supervised the Pomona, Calif., plant where the Divad models were produced, and chief Divad project officers David L. McPherson and James C. Hansen Jr..

The individuals face maximum sentences of five years in prison, and they and the company face maximum fines of $70,000 each.

Federal officials said the allegations were sparked by a 1983 Pentagon audit and were not known when Beggs was named to head the nation's space agency.

General Dynamics lost a competition with Ford Aerospace & Communications Corp. for the Army contract to build the antiaircraft gun. The radar-guided weapon was dogged by controversy since inception, including allegations that the Army withheld poor test results showing that the weapon could not reliably fulfill its mission of shooting down helicopters and planes.

The indictment charges that General Dynamics, using illegal accounting techniques, "understated the true cost" of the two prototype Divad guns that it built for its competition with Ford Aerospace.

Faced with cost overruns on its $40 million Army contract, the indictment charges, the company used two other accounts -- one earmarked for new research and development, the other for preparing new bids and proposals -- to pay for the extra costs that could not otherwise have been reimbursed.

Although the Pentagon provides funding for both accounts, companies are barred from using that money for existing contracts.

Robert C. Bonner, the U.S. attorney in Los Angeles, said the government lost only $3.2 million on overcharges because Pentagon officials did not approve all the claims. He called the indictment part of an effort "to crack down on defense contractors who . . . are pillaging the U.S. Treasury."

The indictment alleges that company executives used complex terminology to make projects such as creation of computer software for Divad appear to be general research not related to the weapon.