A government program that helps struggling homeowners take advantage of low interest rates to cut monthly mortgage payments is providing an unexpected revenue boost to large banks such as Wells Fargo & Co. and J.P. Morgan Chase & Co.

Banks that collect those payments, known as mortgage servicers, could get as much as $12 billion in revenue this year refinancing mortgages under the federal Home Affordable Refinance Program, or HARP, according to data compiled by Nomura Holdings Inc.

Borrowers...