In the long history of troubled relations between the Defense Department and its civilian contractors, few chapters are nastier than the latest dispute between the Navy and the Electric Boat division of General Dynamics Corp.

After years of cost overruns, faulty workmanship and delayed deliveries on nuclear submarines built at Electric Boat's shipyards in Groton, Conn., the Navy has engaged the company in an open war of angry words and withheld contracts. Each side accuses the other of jeopardizing the nation's security for improper and unjustified reasons.

To a shipbuilding industry counting on contracts from an expanding Navy to replace its dwindling orders for commercial ships, the feud has brought deep anxiety, because the Navy is threatening to resume submarine construction at its own yards, a move that could cut the private shipbuilders out of some vitally needed business.

Secretary of the Navy John Lehman has publicly accused Electric Boat of "preposterous" conduct that attempts to make the taxpayers foot the bill for the company's "faulty performance."

Electric Boat, the nation's only builder of Trident nuclear submarines and one of only two shipyards building nuclear attack subs, accused Lehman of "grievous" misjudgment that could force the company to lay off 3,000 workers and jeopardize the entire nuclear submarine program.

Electric Boat says, and Navy officials agree, that many of the yard's problems have been corrected and its performance has greatly improved, but bitter differences over the responsibility for past mistakes remain unresolved.

Lehman demanded that Electric Boat withdraw a claim for reimbursement of $18.9 million in costs incurred in building the S.S. Bremerton. He said "platoons of corporate lawyers" would not be allowed to impose the principle that "the government always pays." He also said the Navy would press counterclaims and threatened to withhold further contracts from Electric Boat.

In a statement issued by the parent General Dynamics, the company said, "The Navy has a motive other than Electric Boat's performance" for its actions. General Dynamics pledged to "pursue its legal entitlement in this matter to its conclusion."

And in a separate but related episode, Electric Boat officials complained privately to senior Navy officials that Adm. Hyman Rickover, the 81-year-old father of the nuclear Navy, had jeopardized the safety of two submarines during sea trials by failing to issue the proper commands on time while he was in charge.

Rickover has been an outspoken critic of Electric Boat's shipbuilding performance. Electric Boat memos referring to Rickover as "the old man" were delivered to Adm. Thomas B. Hayward, the chief of naval operations, and other top admirals by P.T. Veliotis, Electric Boat's general manager.

Those memos, which quoted Navy officers as questioning Rickover's judgment and asserting that "nobody can control Rickover," were promptly leaked to the press, apparently by Rickover's foes within the Navy.

Electric Boat is a cornerstone of the Navy's future. The company has billions of dollars in contracts to build eight Trident submarines and 12 attack subs. Neither side in this marriage of convenience can afford a divorce, but the relationship has been stormy for much of the past decade.

The Navy went on the offensive against Electric Boat in March. Vice Adm. Earl B. Fowler, commander of the Naval Sea Systems Command, briefed Congress on the troubled nuclear sub construction program and reported that Electric Boat was plagued by faulty welding, wrongly coded steel parts and sloppy management.

About the same time, Navy Secretary Lehman suspended bidding competition on three new attack submarines, opening negotiations with Newport News Shipbuilding Co. and excluding Electric Boat from consideration.

Electric Boat says those actions were taken despite the fact that the company's problems "had already been solved" and the Navy knew they had been solved.

According to officials of General Dynamics and Electric Boat, a special committee appointed jointly by Lehman and the company then studied the Navy's complaints and "reported to the secretary of the Navy that Electric Boat's problems were behind them, that they could meet their schedules and that they could deliver at the specified rate."

The Navy, however, raised new questions about Electric Boat's management and manpower and refused to award the company any new contracts, forcing the shipyard to lay off, by its account, 2,000 of its 24,000 workers.

In June, the company filed a claim for $18.9 million in costs it says it incurred in meeting Navy inspection requirements and making welding repairs on the Bremerton. The claim was filed against the organization that has been the insurer on naval shipbuilding programs since 1942 -- the Navy itself.

Lehman gave his public response in a National Press Club speech on Aug. 19. Electric Boat, he said, "has recently injected a new and very disruptive element into our business relations."

Urging the firm to withdraw the claim, he said, "For a corporation to pursue, as a policy, the principle that the taxpayers should pay for the mistakes, the negligence, the poor workmanship or the inadequate management of that company in carrying out a contract with the government is preposterous."

Saying that Electric Boat was "15 ship years" behind schedule in delivering submarines and lacked "manning levels" adequate to justify taking on new orders, Lehman demanded that the firm withdraw its compensation claim.

"I am here today," Lehman said, "to announce that the Department of Defense will not tolerate such corporate attitudes. They are unacceptable. We will not subscribe to the notion that the government always pays."

General Dynamics responded that the Navy was holding vital contracts "hostage" and charged, "The tactics being employed by the Navy to force withdrawal of Electric Boat's insurance reimbursement request are in direct contravention of fair play. In our society of law, it is not the government's right to employ strong-arm methods" to settle legal issues. The company said it would press the $18.9 million claim and file others.

Last week 15,000 Electric Boat employes petitioned President Reagan to intervene. They asked him to assure the company its "day in court," saying that "the need for work at Electric Boat and the need for submarines by this country are too important to get halted by a matter that belongs in court."

The Navy may be trying to tone down the quarrel. George A. Sawyer, assistant Navy secretary for shipbuilding, said in an interview that Electric Boat was "not at all" precluded from bidding on future contracts. He said he seeks a "constructive relationship. Name-calling and vendetta serve no purpose."

Electric Boat, he said, "has the physical facilities and the personnel to perform and is delivering a quality product at the present time."

Rickover, who was accused in the Electric Boat memos of failing to issue vital commands to prevent the untested subs from going into dangerous reverse dives, said through a Navy spokesman that he would have no comment.

Hayward, in a letter to Veliotis, did not mention Rickover by name, but said he was satisfied that the maneuvers undertaken by the subs were "not hazardous."