NEW YORK, N.Y. – The nation’s largest bank, JPMorgan Chase & Co., will pay $614 million and improve mortgage lending practices under a deal announced Tuesday to settle claims it approved thousands of unqualified home mortgage loans for government insurance and refinancing since 2002, costing the government millions of dollars when the loans defaulted.

U.S. District Judge J. Paul Oetken in Manhattan approved the deal, which calls for JPMorgan to pay the money within a month and install an improved quality control program to review loans it underwrites using a federally maintained software application that determines if a loan qualifies for government insurance.

JPMorgan said in a statement that its deal with federal prosecutors, the Federal Housing Administration, the U.S. Department of Housing and Urban Development and the U.S. Department of Veterans Affairs “represents another significant step in the firm’s efforts to put historical mortgage-related issues behind it.”

The New York-based company said it had already reserved the money for the settlement and any financial impact from exposure to future claims wasn’t expected to be significant.

In a release, U.S. Attorney Preet Bharara said the company had for years participated in federally subsidized programs meant to make homes more affordable for millions of Americans.

“Yet, for more than a decade, it abused that privilege,” he said. “JPMorgan Chase put profits ahead of responsibility by recklessly churning out thousands of defective mortgage loans, failing to inform the government of known problems with those loans and leaving the government to cover the losses when the loans defaulted.”

The prosecutor acknowledged, however, that the company had accepted responsibility and promised to reform the flawed practices.

The government said the bank approved thousands of loans for government insurance or refinancing that didn’t meet the requirements of federal programs and failed to self-report hundreds of loans it identified as having been affected by fraud or other deficiencies. It also regularly submitted loan data that lacked integrity because it was not based on documents or other information it possessed when employees submitted the data, the government said.

Associate Attorney General Tony West said the deal “recovers wrongfully claimed funds for vital government programs that give millions of Americans the opportunity to own a home and sends a clear message that we will take appropriately aggressive action against financial institutions that knowingly engage in improper mortgage lending practices.”

In November, JPMorgan agreed to pay $13 billion to settle a civil inquiry into its sales of low-quality mortgage-backed securities that collapsed in value in the 2008 financial crisis. It also announced it had reached a $4.5 billion settlement with 21 major institutional investors over mortgage-backed securities issued by it and Bear Stearns between 2005 and 2008.

Last month, it agreed to pay more than $2.5 billion for ignoring obvious warning signs of Bernard Madoff’s massive Ponzi scheme. Madoff, who is serving a 150-year prison sentence after admitting the fraud, squandered nearly $20 billion from thousands of investors over several decades.

JPMorgan set aside $23 billion last year to cover the settlements and other costs related to its legal troubles.