E. C. Ernst Inc., the big electrical contracting firm that has been having financial problems for months, yesterday filed a petition for reorganization under Chapter XI of the federal bankruptcy laws.

The action was taken, a company official said, after several banks called due almost $21 million of Ernst's $25 million in debt and attached $925,000 in Ernst's bank accounts.

When a company files for bankruptcy under Chapter XI, it is allowed to postpone paying its creditors while it reorganizes and works out a plan for repayment.

Ernst lost $5.8 million on sales of $129 million last year and reported a loss of almost $7 million for six months ended Sept. 30.

Since then, the company has been sued by stockholders for allegedly filing false earnings statements and has reorganized its top management several times.

In the latest management move, Joseph E. Griffin, 61, yesterday was elected chairman of the board and chief executive officer. A former Ernst executive who left in 1972, Griffin had been acting chief executive of Ernst since Oct. 18, when he rejoined the company as senior vice president.

He also was elected to the board of directors yesterday, as four other board members resigned: Charles S. Jones, Walter V. Knopp, David L. Eggers and Charles L. Scharfe Jr., who had been chief executive since August.

Along with E. C. Ernst Inc., a public company whose shares are traded on the American Stock Exchange, two subsidiaries filed Chapter XI petitions, E. C. Ernst Midwest Inc. and E. C. Ernst International Corp.

Ernst and its affiliates are electrical construction firms, doing large electrical work throughout the world.

"Although the company has an excellent backlog of construction orders, it is presently short of cash," an official Ernst representative said yesterday after announcing the bankruptcy filing.

He said Ernst is "asking its creditors to have faith in the business."

Ernst reportedly had been slow in paying its bills lately, but had been able to meet its payrolls on time. Construction work now being done by the company is not expected to be delayed or halted by the decision to file under Chapter XI.

The spokesman said the company and its subsidiaries "will propose plans which its believes will be accepted by their creditors" for repaying its debts.

It was not clear yesterday what impact the Chapter XI filing will have on a hearing scheduled for Monday in a lawsuit seeking to block the merger of Ernst and L.K. Comstock, another large electrical construction firm.

Scharfe, who quit as Ernst's chairman last week, had been the head of Comstock before the two companies joined in June. The companies continue to operate separately. Comstock specializes in utility and heavy electrical construction; Ernst does mostly commercial and institutional electrical work.

Comstock, which has offices in Danbury, Conn., did not file a Chapter XI petition.

Ernst's financial problems appeared unexpectedly earlier this year. The company profited for the first three quarters of its fiscal year, but when the year ended March 31, Ernst restated its figures and showed a $5.8 million loss.

The losses continued this year, with the company reporting a $3.9 million deficit for its first quarter that increased to $7 million in the six months ended Sept. 30.

A lawsuit filed against Ernst by a stockholder charges the company overstated its earnings by improperly including income from three longterm contracts that had not been completed.

Auditors forced the company to restate its earnings, resulting in the unexpected losses.

Questions about the accuracy of reports Ernst filed with the SEC lead the company to postpone indefinitely plans to sell almost $11 million in debentures to raise new capital.

Griffin, who took the reins of the company yesterday, is an accountant. He served as chief financial officer for the company in 1971 and 1972. He quit to become a financial consultant, then was brought back to help Ernst manage its cash flow.