In this residential mortgage foreclosure action, the court adopts the approach of the Third Restatement of Property: Mortgages that equitable subrogation is appropriate when loan proceeds from refinancing satisfies the first mortgage, the second mortgage is paid in full as part of the transaction, and the transaction is based on a discharge of the second mortgage, so long as the junior lienor, here defendant, is not materially prejudiced. The court concludes that under such circumstances, equitable subrogation should not be precluded by the new lender's actual knowledge of the intervening mortgage. By limiting the first lien priority of plaintiff's mortgage to the balance due on the prior first mortgage at closing, the superior lien balance owed by the borrowers was not increased. Under these circumstances, the junior lienholder is not materially prejudiced by subrogating plaintiff's mortgage.