JPMorgan Chase illegally allowed Lehman Brothers, the investment bank whose 2008 bankruptcy brought the financial system to the brink of collapse, to count customers’ money as its own, according to federal regulators.

The arrangement boosted the amount that Lehman could borrow from JPMorgan, where the customers’ money was deposited, regulators charged Wednesday.

Then, at the height of the financial crisis, JPMorgan refused to release the customer funds for about two weeks, until regulators ordered it to do so, regulators charged.

The charges were spelled out in an enforcement action against JPMorgan by the Commodity Futures Trading Commission (CFTC).

Without admitting or denying wrongdoing, JPMorgan agreed to pay $20 million to settle the civil case.

The matter adds another dimension of alleged lawbreaking to the history of Lehman’s downfall. It was also another vivid illustration that, even in highly regulated modern financial firms, basic controls can break down.

Last fall, the big brokerage firm MF Global collapsed with as much as $1.6 billion of customer funds missing and unaccounted for. There, too, it appears that clients’ money was treated as if it belonged to the firm.

The customer deposits at issue in the Lehman matter, which totaled from about $250 million to more than $1 billion at any one time, were supposed to have been held for customers who were using Lehman as a broker for futures and options trades.

Federal law declares that such funds should not be commingled with those of the firm, the commission said.

“The laws . . . impose critical restrictions on how financial institutions can treat customer funds,” CFTC enforcement director David Meister said in a statement. “As should be crystal clear, these laws must be strictly observed at all times, whether the markets are calm or in crisis.”

JPMorgan refused to release the funds in September 2008, partly because they were tied to Lehman’s borrowing from JPMorgan, the CFTC said. JPMorgan also cited “its inability to verify” that the funds belonged to customers, the commission said.

In a statement Wednesday, JPMorgan said it “mistakenly factored the balance . . . into a daily calculation of [Lehman Brothers Inc.] assets to determine the amount of credit the firm was willing to extend to [Lehman Brothers Inc.].”

No customer funds were lost, and the commission did not accuse JPMorgan of intentional wrongdoing, JPMorgan said.

Lehman imploded largely under the weight of its borrowing. The New York attorney general’s office in 2010 charged that Lehman’s audit firm helped it engage in “a massive accounting fraud” that concealed the extent to which the firm was leveraged with debt.

Wednesday’s charges involved loans that JPMorgan made to Lehman on an intraday basis — in installments of no more than a day. The amount JPMorgan would lend was pegged to the amount of cash and securities Lehman had on deposit with JPMorgan.

Lehman began counting customer assets toward that total in 2006, and JPMorgan “acceded” to the practice, the commission said.

JPMorgan said the amount by which the alleged wrongdoing increased Lehman’s borrowing was relatively small. According to the CFTC charging document, over a period of almost two years, it boosted Lehman’s borrowing under the intraday program by as much as 5 percent at any point in time.

The $20 million penalty is little more than a pinprick for a firm of JPMorgan’s size. For 2011, it reported a profit of $19 billion.