Target agreed to a $39 million settlement with several U.S. banks on Wednesday over a data breach that affected roughly 40 million customers.

The banks lost millions when they were forced to reimburse customers who lost money in the massive 2013 hack of Target's database.

The banks, which service MasterCard, filed a class action lawsuit against Target after rejecting an earlier $19 million deal. MasterCard had tentatively approved that deal in April on behalf of its card issuers, but several of the banks rejected it.

The banks in the class action lawsuit include Umpqua Bank, Mutual Bank, Village Bank, CSE Federal Credit Union, and First Federal Savings of Lorain.

Related: Target just made its credit card a lot safer

Charles Zimmerman, the lawyer representing the banks, told CNNMoney that he is "very pleased" that they held their ground and that they "will be compensated in a more appropriate manner -- based upon what they really lost."

The settlement is the latest in a series of payouts Target has made.

In August, Target settled with Visa for $67 million over the data hack. And in March, Target settled a federal class action lawsuit brought by customers for $10 million.

A spokesperson for Target said the company was "pleased that the process is continuing to move forward.