When First Niagara Financial Group Inc. agreed in July to buy Harleysville National Corp. for $237 million in an all-stock deal, an important matter was left unresolved:

How would Harleysville meet a demand by federal banking regulators, disclosed in early June, that it raise $65 million to $120 million to improve its financial position?

The planned all-stock sale of the Montgomery County bank to First Niagara of Buffalo would not fill the holes left in Harleysville National's balance sheet by bad loans to home builders until the deal closed.

Harleysville's continued need for capital led to First Niagara's contribution of $35 million last week, allowing Harleysville to meet the regulatory requirements of a well-capitalized bank for the first time since September 2008, Harleysville said yesterday.

Harleysville's chief executive, Paul Geraghty, expressed relief: "Obviously, no board of directors or management team wants to be operating a bank in noncompliance with regulatory directives."

The $35 million was called a loan, but no payments will be made on it as long as the sale of Harleysville to First Niagara stays on track.

In connection with the $35 million capital infusion, the Office of the Comptroller of the Currency extended the deadline for Harleysville to bring its balance sheet into compliance with federal regulations to March 31 from June 30, Harleysville said. The banks expect the purchase deal to be completed well before the new deadline.

First Niagara is prepared to provide an additional $15 million in capital and may also buy up to $80 million in commercial loans and commercial real estate loans from Harleysville, as well as allow the Montgomery County bank to begin making loans on its behalf in the Philadelphia region. Those moves give Harleysville "flexibility for some of our better customers that want and need more credit," Geraghty said.