Wells Fargo has agreed to spend at least $42 million to settle allegations that it neglected the maintenance and marketing of foreclosed homes in black and Latino neighborhoods across the country, the National Fair Housing Alliance announced Thursday.

A year-long investigation by the advocacy group found that homes serviced by Wells Fargo in minority communities were far more likely than those in white areas to be left in disrepair, with broken windows, unkempt yards or water damage. These home were also less likely to have for-sale signs than ones in predominantly white neighborhoods.

Under the agreement, Wells Fargo, which did not admit any wrongdoing, will provide $27 million to nonprofit groups to promote homeownership, neighborhood stabilization and property rehabilitation in minority communities in 19 metropolitan areas, including Prince George’s County and the District. It will also provide $11.5 million to the Department of Housing and Urban Development to help 25 other cities.

“Many neighborhoods across the country have been seriously damaged by the foreclosure crisis,” said Shanna Smith, president and chief executive of the alliance. This agreement “will help lay the foundation for the industry to get some of those neighborhoods back on their feet.”

The agreement addresses one of the lingering scars of the housing crisis. As the number of foreclosures climbed in the aftermath of the housing crash, lenders scrambled to offload foreclosed properties, with many piling up in minority neighborhoods where there was a high concentration of subprime loans. Communities have been eager to see these vacant properties sold because over time they can bring down property values and attract crime, consumer groups say.

Areas such as Prince George’s are still struggling to rebound. About 7.4 percent of homes in that area, known for its concentration of affluent African Americans, were empty in 2010, according to the Census Bureau, compared with 4.6 percent in Prince William County, another hard-hit area.

Even as home prices rise in Prince George’s, the county still has about 51,000 foreclosed homes on the market, according to the county Department of Environmental Resources.

The agreement, reached Wednesday, resolves an April 2012 complaint that the advocacy group filed with HUD. HUD did not rule on whether Wells Fargo violated any fair housing laws, but the agreement closes the case.

As part of the agreement, Wells Fargo agreed to give borrowers who plan to live in a home after the purchase priority in the bidding process over investors eager to snap up cheap houses to rent out or flip. Traditional buyers will get more time before investors, which has increasingly included Wall Street firms, are allowed to make an offer.

The bank also agreed to develop a fair housing training program for its employees and the real estate agents who sell foreclosed properties. In addition, Wells Fargo is giving $250,000 to the housing alliance to sponsor seminars on foreclosure prevention and $300,000 to hold two conferences on fair housing laws.

“These agreements represent a significant commitment . . . to invest in programs that will strengthen minority communities impacted by foreclosures,” said J.K. Huey, senior vice president of Wells Fargo Home Mortgage.

The housing alliance has filed two similar complaints against Bank of America and U.S. Bank, but negotiations on a deal have reached an impasse, according to the group.

Both banks denied the group’s allegations. In a statement, Bank of America said, “We strongly deny NFHA’s allegations and stand behind our property maintenance and marketing practices.”

U.S. Bank said it does not service some of the homes identified by the group. “When we do own a property, we have a strong and comprehensive process in place to regularly inspect and maintain properties to marketing standards where we have legal access, regardless of their location,” the company said in a statement.