WASHINGTON—Wells Fargo & Co. on Thursday agreed to pay $34.8 million to settle allegations it received payments from a title firm in exchange for business, as a U.S. regulator scrutinizes such relationships in the real-estate industry.

As part of the same action, J.P. Morgan Chase & Co. agreed to pay $900,000. The banks settled civil claims brought by the Consumer Financial Protection Bureau and the Maryland attorney general’s office.