Bank of America agreed Wednesday to pay $335 million to settle federal claims that its Countrywide Financial unit charged black and Hispanic borrowers higher mortgage fees in the lead up to the financial crisis and steered them into riskier loans than their white counterparts.

Obama administration officials said the settlement, the largest ever for fair-lending claims, came after investigators reviewed more than 2.5 million home loans originated by Countrywide during the housing boom.

Investigators concluded that Countrywide charged more than 200,000 blacks and Hispanics higher fees and interest rates than comparable white borrowers between 2004 and 2008. In addition, officials claim the firm advised more than 10,000 minority borrowers to take riskier and more costly subprime loans, even though they could have qualified for more traditional mortgages.

“The department’s actions against Countrywide makes clear that we will not hesitate to hold financial institutions accountable, including one of the nation’s largest, for discrimination,” said Attorney General Eric H. Holder Jr., flanked at an afternoon news conference by other administration officials and Illinois Attorney General Lisa Madigan, who has long pursued Countrywide’s actions in her state. “These institutions should make judgments based on applicants’ creditworthiness, not on the color of their skin.”

The California-based company became one of the country’s most prolific subprime lenders but ultimately fell victim to its own reckless lending practices. Bank of America bought the failing lender in 2008, just as the financial crisis was gaining steam.

Officials noted that Countrywide’s discriminatory practices stretched across 41 states and the District of Columbia. Nearly a third of the cases took place in California, an epicenter of the housing boom and subsequent bust. Holder cited one example from 2007, in which he said a black customer in Los Angeles paid $1,200 more in fees on a $200,000 loan than a similarly qualified white borrower.

Officials said Countrywide routinely allowed its loan officers and mortgage brokers to alter a loan’s interest rate and other fees subjectively, rather than based solely on a borrower’s credit qualifications, and to steer black and Hispanic borrowers into subprime loans with more onerous terms.

“If you were African American or Latino, and you went to Countrywide for a loan, and you were qualified, you likely paid more simply because of the color of your skin,” said Tom Perez, assistant U.S. attorney general for the civil rights division, adding that the practices “effectively amounted to a race-based surtax.”

Dan Frahm, a Bank of America spokesman, said Wednesday that the allegations pre-date the bank’s acquisition of Countrywide, and that Bank of America has continued to try to resolve the problems created by a lender that became synonymous with questionable practices and toxic loans.

“We reached this settlement to resolve issues about Countrywide’s alleged historic practices that occurred before Bank of America acquired the company,” Frahm said in a statement. “We are committed to fair and equal treatment of all our customers, and will continue to focus on doing what’s right for our customers, clients and communities.”

The ill-fated purchase of Countrywide and its troubled loan portfolio has proved an albatross for Bank of America, triggering billions of dollars in lawsuits, legal battles and settlements. “There aren’t many days that I get up and think positively about the Countrywide transaction,” Bank of America chief executive Brian Moynihan said in a conference call earlier this year.

Wednesday’s settlement, which requires court approval, was filed in the U.S. District Court for the Central District of California alongside the government’s civil complaint detailing Countrywide’s misdeeds. Officials said the $335 million in penalties would be distributed to individual borrowers based on the harm they suffered.

The Countrywide case is just one of many efforts by the government to respond to abuses leading up to the housing crisis and in its aftermath.

The Justice Department last year created a unit to investigate unfair lending practices. Various state and federal officials have undertaken a variety of other inquiries and lawsuits against lenders on multiple fronts including the way they originated loans and the manner in which they packaged and sold mortgages to investors on Wall Street. For more than a year, a group of state attorneys general and administration officials have been negotiating a settlement with large mortgage servicers over shoddy foreclosure practices that, if finalized, could result in more than $20 billion in penalties.

News of the settlement sent Bank of America’s shares to $5.23, up more than 1 percent on the day but down nearly two-thirds from where they stood at the beginning of the year.