This is a case of first impression concerning the doctrine of equitable subrogation. The defendant, Lois J. Ogan, appeals from a grant of summary judgment in favor of the plaintiffs, East Boston Savings Bank (East Boston) and Edward W. Toner, Jr. The Land Court granted a declaratory judgment in favor of the plaintiffs and ruled that the defendant’s mortgage was subordinate to both the equity interest held by Toner and *328the mortgage interest of East Boston. The defendant appealed, and we transferred the case to this court on our own motion. We affirm the Land Court’s judgment and hold that equitable subrogation applies in cases like the one before us today.
1. Facts. The following facts are undisputed. Steven and Jeffery Kline purchased a condominium unit (property) as tenants in common for $227,000 on September 19, 1988, and financed their purchase, in part, with a $187,500 mortgage loan from Eastern Savings Bank (ESB). On February 9, 1989, Steven Kline granted a second mortgage in the amount of $50,000 in his one-half undivided interest in the property to the defendant. This mortgage indicated that it was “subject to a mortgage to the Eastern Savings Bank.” After this transaction the property was subject to the first mortgage to ESB, and the second mortgage to the defendant.
The Klines sold the property to Toner on November 10, 1994, for $183,000. As consideration, Toner gave a mortgage secured by the property for $130,000 to East Boston, and he provided $54,407.63 from his own funds. The balance of the ESB mortgage, $176,948.65, was discharged at the closing. This transaction was recorded promptly but, unknown to the parties at the time, East Boston’s closing attorney never discovered the defendant’s intervening mortgage. After the sale, on the record the property was subject to the mortgage of the defendant followed by the new mortgage to the plaintiff, East Boston.
2. Background. We have long held that our courts have broad power over mortgages. These powers have been exercised in order, for example, to reform mortgages, see General Bldrs. Supply Co. v. Arlington Coop. Bank, 359 Mass. 691, 696-697 (1971) (discussing reformation of mortgages), and cases cited, to restore once-extinguished mortgages, see Childs v. Stoddard, 130 Mass. 110, 112 (1881) (mortgagee can seek to have discharge of mortgage set aside); Bruce v. Bonney, 12 Gray 107, 112 (1858) (same), and to adjust priorities among existing mortgages, see Worcester N. Sav. Inst. v. Farwell, 292 Mass. 568, 574 (1935) (subrogation adjusts priorities among mortgages). As both parties acknowledge: “It is the general rule that, where a mortgage has been discharged by mistake, equity will set the discharge aside and reinstate the mortgage to the position the parties intended it to occupy, where the rights of intervening lienors have not been affected.” North Easton Coop. Bank v. MacLean, 300 Mass. 285, 292 (1938).
Subrogation is among these long-recognized powers. See *329Worcester N. Sav. Inst., supra, and cases cited. It allows “the substitution of one person in place of another ... so that he who is substituted succeeds to the rights of the other.” Provident Coop. Bank v. James Talcott, Inc., 358 Mass. 180, 188 (1970), quoting Jackson Co. v. Boylston Mut. Ins. Co., 139 Mass. 508, 510 (1885). The question whether to apply subrogation depends on a balance of the interests of the competing mortgagees because “[t]he right to subrogation rests upon equity.” Massachusetts Hosp. Life Ins. Co. v. Shulman, 299 Mass. 312, 316 (1938), and cases cited. The court guards against the unjust enrichment of either party by granting to the later mortgagee the priority status intended by the parties to that transaction, only so long as the interests of the intervening mortgagee are not prejudiced.2
Today we are urged by the plaintiffs to uphold the decision of the Land Court and to extend the doctrine of equitable subrogation. We have not previously addressed the question whether, and to what extent, equitable subrogation applies where a mortgage is extinguished as part of a sale. We have applied subrogation to a refinancing transaction. See Provident Coop. Bank, supra; North Easton Coop. Bank, supra at 292.3 Because we find that the equities are substantially similar in refinancing and sales transactions, and that application of equitable subrogation to a sale is consistent with our precedent, we hold that equitable subrogation applies in this case.
3. Discussion. Equitable subrogation is an exception to the basic principle that determines priority among mortgages, “first in time is first in right.” Where equitable subrogation applies:
*330“One who fully performs an obligation of another, secured by a mortgage, becomes by subrogation the owner of the obligation and the mortgage to the extent necessary to prevent unjust enrichment. Even though the performance would otherwise discharge the obligation and the mortgage, they are preserved and the mortgage retains its priority in the hands of the subrogee.”
Restatement (Third) of Property (Mortgages) § 7.6(a) (1997). In other words, the new mortgage given by a mortgagor, who used the proceeds of the new mortgage to extinguish an earlier mortgage, may receive the same priority once given to the earlier mortgage.
Before equitable subrogation applies, a court must determine: “(1) the subrogee made the payment to protect his or her own interest, (2) the subrogee did not act as a volunteer,[4] (3) the subrogee was not primarily liable for the debt paid, (4) the subrogee paid off the entire encumbrance, and (5) subrogation would not work any injustice to the rights of the junior lien-holder.” Mort v. United States, 86 F.3d 890, 894 (9th Cir. 1996), citing Han v. United States, 944 F.2d 526, 529 (9th Cir. 1991). It is “a broad equitable remedy” and, depending on the individual case, it may apply even where one or more of these factors is absent. Mort, supra.
A court applying equitable subrogation must ensure that the intervening mortgagee is not unjustly enriched by succeeding to first priority, but it also must ensure that the intervening mortgagee does not receive a lower priority as a result of the subrogee’s mistake. Thus, subrogation will not apply to the extent it prejudices the intervening mortgagee. For instance, subrogation will only occur to the extent that funds are owing on the original mortgage when the mistake is made. See Provident Coop. Bank, supra at 189. “The payor is subrogated only to the extent that the funds disbursed are actually applied toward the payment of the prior lien. There is no right of subro-gation with respect to any excess funds.” Restatement, supra at § 7.6 comment e, at 520.
*331A second mortgagee, however, accepts risks inherent in that security. These include, for instance, a renewal or an extension of time for payment on the original mortgage. See Guleserian v. Fields, 351 Mass. 238, 242-243 (1966). Actions like these cannot be considered prejudicial to the junior mortgagee and, in fact, do not require the approval of the junior mortgagee. See id. at 243. Other situations may be different. For example, we have recognized that a first mortgage holder may not unduly prejudice the junior mortgagee when modifying a first mortgage. See Shane v. Winter Hill Fed. Sav. & Loan Ass’n, 397 Mass. 479, 485-486 (1986).
The court must also examine the actions of the subrogee. The degree of knowledge attributable to a subrogee concerning the existence of the intervening mortgage may nullify equitable subrogation. Some courts subrogate without regard for the subrogee’s knowledge. See Klotz v. Klotz, 440 N.W.2d 406, 409-410 (Iowa Ct. App. 1989); Trus Joist Corp. v. National Union Fire Ins. Co., 190 N.J. Super. 168, 179 (App. Div. 1983), rev’d on other grounds, 97 N.J. 22 (1984); Providence Inst. for Sav. v. Sims, 441 S.W.2d 516, 520 (Tex. 1969). See also Restatement, supra at Reporters’ Note at 529. Others will deny subrogation where the subrogee has actual knowledge, but will permit it where the subrogee has constructive knowledge. See, e.g., Smith v. State Sav. & Loan Ass’n, 175 Cal. App. 3d 1092, 1098 (1985); United Carolina Bank v. Beesley, 663 A.2d 574, 576 (Me. 1995). Other courts deny equitable subrogation to a subrogee who has mere constructive knowledge of the intervening lien. See Independence One Mtge. Corp. v. Katsaros, 43 Conn. App. 71, 74-75 (1996).
We decline to adopt a bright line rule concerning subrogee knowledge. We are persuaded by the reasoning of courts that not only allow subrogation where the subrogee has actual or constructive knowledge of the intervening mortgage, but also look to equity to decide if subrogation is inappropriate. See Davis v. Johnson, 241 Ga. 436, 439-440 (1978). “[Kjnowledge is not necessarily fatal to the grantee’s claim of subrogation, if equity would nonetheless dictate the recognition of subrogation.” Restatement, supra at § 7.6 comment d, at 518. The court must determine, under the circumstances, if the subrogee acted with sufficient knowledge to merit denying subrogation where it would otherwise be the correct result.
Subrogee culpability, like their level of knowledge concern*332ing intervening liens, is not susceptible to a clear rule that might distinguish acts that negate the use of subrogation from those that do not. The subrogee’s behavior is an important consideration that the court must balance in its equitable analysis of the interests of both mortgagees. See Worcester N. Sav. Inst. v. Farwell, 292 Mass. 568, 574 (1935) (“Negligence of one which does not induce a change of position of another is not a bar to recovery in cases of subrogation”). Other courts also have taken this approach. See Davis, supra at 440 (“The senior secured party’s lack of diligence in failing to discover the existence of the intervening hen becomes material only where this has prejudiced the rights of the intervening lienor”); United Carolina Bank, supra at 576 (subrogation available to mortgagee who negligently performs title search).
4. Present case. We reject the defendant’s arguments and uphold the Land Court.
The defendant argues that there is a material distinction between a mortgage given during a refinancing and one given as part of a sale. She argues that in a sale the parties intend to extinguish the original mortgage; they do not make a mistake that would justify equitable subrogation. Subrogation, however, can be appropriate in the absence of a mistake. See Restatement, supra at § 7.6(b). As discussed above, the distinction between a sale and a refinancing exists, but subrogation arising out of either context yields the same result.
The defendant next argues that the debt and the mortgage are extinguished in a sale, and, therefore, nothing remains to be “assigned” to the subrogee. The defendant’s argument is misplaced because the cases she cites address only the distinction between an assignment and a release, a distinction not at issue here. See Heller Fin. v. Insurance Co. of N. Am., 410 Mass. 400 (1991); Widett & Widett v. Snyder, 392 Mass. 778 (1984); Gleason v. Dorney, 332 Mass. 646 (1955). In the present case subrogation resurrects a debt from a transaction which would otherwise extinguish it. The Restatement, supra at § 7.6, in its definition of subrogation, states: “Even though the performance would otherwise discharge the obligation and the mortgage, they are preserved and the mortgage retains its priority in the hands of the subrogee.” Our precedent also recognizes that subrogation reestablishes a once-extinguished debt. See Piea Realty Co. v. Papuzynski, 342 Mass. 240, 246 (1961) (“Equitable considerations, however, may affect the questions *333whether mortgage security has been discharged or [if discharged] will be reinstated and whether, by subrogation or upon analogous principles, it still remains available to a mortgage creditor”).
The defendant also argues that equitable subrogation will undermine the recording system by allowing buyers and lenders who ignore or who miss recorded liens to seek subrogation. The defendant asserts that this will create doubt about every extinguished mortgage on record in the Commonwealth.
Equitable subrogation will not undermine the recording system. As discussed earlier, equitable subrogation is an extension of our long-standing equitable power over mortgages. Equity guards against any potential injustice created by subro-gation against those who rely on the recording system. A mortgagee whose mortgage is subrogated to the original mortgage but who fails to record its own mortgage would not have priority over another who acquired an interest in good faith during the time between subrogation and the recording of the subrogated mortgage. See Restatement, supra at § 7.6 illustration 30, at 523. In Massachusetts, that subsequent purchaser would prevail over the subrogee under the recording statute as long as the purchaser did not have actual notice of the transaction. See G. L. c. 183, § 4. Likewise, the court could deny equitable subrogation to a mortgagee who unnecessarily delays before demanding subrogation because this could prejudice the intervening mortgagee, or one who pinchases the intervening mortgagee’s interest. See Restatement, supra at § 7.6 illustration 31, at 524.
Applying the elements of equitable subrogation to this case leads us to conclude that the plaintiffs’ mortgage is superior in priority to the defendant’s mortgage. The plaintiffs’ payment to extinguish the original mortgage was made to protect their own interest. They did not act as “volunteers” because they purchased the property and mortgaged it at sale. Neither plaintiff was primarily liable for the original mortgage and they combined to extinguish the entire debt owing. Finally, subrogation will not work any injustice on the defendant. When the plaintiffs purchased the property, the defendant’s mortgage was subordinate to ESB’s first mortgage, which secured a debt of $176,948.65. If the plaintiffs are subrogated to the priority position of that original mortgage, the defendant will be in the same, or better, position as she was when it acquired its interest *334because it will be behind a first mortgage of only $130,000. If equitable subrogation is not applied, the defendant will be unjustly enriched because she will ascend to first priority through no act of her own.
Over-all considerations of fairness support this decision. The plaintiffs expected to have first priority and paid a price that reflected that expectation. They had only constructive notice of the defendant’s mortgage and mistakenly overlooked it. This error is not egregious enough to defeat their claim for equitable subrogation. In addition, the plaintiffs requested subrogation without undue delay.
In contrast, the defendant’s rights are not harmed by application of equitable subrogation. The defendant’s ability to foreclose on the property is not affected, and the probability that she will receive a surplus from a foreclosure of the senior mortgage has increased under the smaller East Boston mortgage. Finally, being subordinate to an unknown party will not harm the defendant.
5. Conclusion. We hold that the plaintiffs are entitled to be equitably subrogated to the priority position of the original mortgage and affirm the judgment of the Land Court.
So ordered.
Some courts, in applying our case law in this area, understandably have termed our subrogation theory to be one of “unjust enrichment” because of the importance we have placed on balancing the interests of all mortgagees. See Progressive Consumers Fed. Credit Union v. United States, 79 F.3d 1228, 1236-1238 (1st Cir. 1996).
The Restatement (Third) of Property (Mortgages) (1997) distinguishes between sale and refinancing contexts. Subrogation is appropriate in a sale transaction, see Restatement, supra at § 7.6, but refinancing completed by the original mortgagee creates a replacement mortgage. See id. at § 7.3. In both instances, the later mortgage receives the same priority as the original mortgage. A distinction is necessary because the refinancing mortgagee, by definition, “cannot be subrogated to [his or her] own previous mortgage.” Id. at § 7.6 comment e, at 519. In theory, the refinancing mortgagee should obtain priority more easily because replacement mortgages are given priority unless the junior mortgagee suffers material prejudice, while subrogation is allowed only to the extent necessary to avoid unjust enrichment.
] “Parties may be considered volunteers if, in making a payment, they have no interest of their own to protect, they act without any obligation, legal or moral, and they act without being requested to do so by the person liable on the original obligation.” Mort v. United States, 86 F.3d 890, 894 (9th Cir. 1996).